PlayAI
Mastra 中的 PlayAI 语音实现通过 PlayAI 的 API 提供文本转语音功能。
🌐 The PlayAI voice implementation in Mastra provides text-to-speech capabilities using PlayAI's API.
使用示例Direct link to 使用示例
🌐 Usage Example
import { PlayAIVoice } from "@mastra/voice-playai";
// Initialize with default configuration (uses PLAYAI_API_KEY environment variable and PLAYAI_USER_ID environment variable)
const voice = new PlayAIVoice();
// Initialize with default configuration
const voice = new PlayAIVoice({
speechModel: {
name: "PlayDialog",
apiKey: process.env.PLAYAI_API_KEY,
userId: process.env.PLAYAI_USER_ID,
},
speaker: "Angelo", // Default voice
});
// Convert text to speech with a specific voice
const audioStream = await voice.speak("Hello, world!", {
speaker:
"s3://voice-cloning-zero-shot/b27bc13e-996f-4841-b584-4d35801aea98/original/manifest.json", // Dexter voice
});
构造函数参数Direct link to 构造函数参数
🌐 Constructor Parameters
speechModel?:
PlayAIConfig
= { name: 'PlayDialog' }
Configuration for text-to-speech functionality
speaker?:
string
= First available voice ID
Default voice ID to use for speech synthesis
PlayAI配置Direct link to PlayAI配置
🌐 PlayAIConfig
name?:
'PlayDialog' | 'Play3.0-mini'
= 'PlayDialog'
The PlayAI model to use
apiKey?:
string
PlayAI API key. Falls back to PLAYAI_API_KEY environment variable
userId?:
string
PlayAI user ID. Falls back to PLAYAI_USER_ID environment variable
方法Direct link to 方法
🌐 Methods
speak()Direct link to speak()
使用配置的语音模型和声音将文本转换为语音。
🌐 Converts text to speech using the configured speech model and voice.
input:
string | NodeJS.ReadableStream
Text to convert to speech. If a stream is provided, it will be converted to text first.
options.speaker?:
string
= Constructor's speaker value
Override the default speaker for this request
返回:Promise<NodeJS.ReadableStream>。
🌐 Returns: Promise<NodeJS.ReadableStream>.
getSpeakers()Direct link to getSpeakers()
返回一个可用语音选项的数组,每个节点包含:
🌐 Returns an array of available voice options, where each node contains:
name:
string
Name of the voice
accent:
string
Accent of the voice (e.g., 'US', 'British', 'Australian')
gender:
'M' | 'F'
Gender of the voice
age:
'Young' | 'Middle' | 'Old'
Age category of the voice
style:
'Conversational' | 'Narrative'
Speaking style of the voice
voiceId:
string
Unique identifier for the voice
listen()Direct link to listen()
此方法不被 PlayAI 支持,会导致错误。PlayAI 不提供语音转文本功能。
🌐 This method is not supported by PlayAI and will throw an error. PlayAI does not provide speech-to-text functionality.
注意Direct link to 注意
🌐 Notes
- PlayAI需要API密钥和用户ID进行身份验证
- 该服务提供两种模型:'PlayDialog' 和 'Play3.0-mini'
- 每个语音都有一个独特的 S3 清单 ID,调用 API 时必须使用该 ID