> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # PlayAI Mastra 中的 PlayAI 语音实现通过 PlayAI API 提供文本转语音功能。 ## 使用示例 ```typescript 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 }) ``` ## 构造函数参数 **speechModel** (`PlayAIConfig`): 文本转语音功能的配置 (Default: `{ name: 'PlayDialog' }`) **speechModel.name** (`'PlayDialog' | 'Play3.0-mini'`): 要使用的 PlayAI 模型 **speechModel.apiKey** (`string`): PlayAI API key。未设置时使用 PLAYAI\_API\_KEY 环境变量 **speechModel.userId** (`string`): PlayAI user ID。未设置时使用 PLAYAI\_USER\_ID 环境变量 **speaker** (`string`): 用于语音合成的默认音色 ID (Default: `第一个可用的音色 ID`) ## 方法 ### `speak()` 使用已配置的语音模型和音色将文本转换为语音。 **input** (`string | NodeJS.ReadableStream`): 要转换为语音的文本。如果提供流,会先将其转换为文本。 **options** (`Options`): 配置选项。 **options.speaker** (`string`): 为本次请求覆盖默认 speaker 返回:`Promise`。 ### `getSpeakers()` 返回可用音色选项的数组,其中每个节点包含: **name** (`string`): 音色名称 **accent** (`string`): 音色的口音(例如 'US'、'British'、'Australian') **gender** (`'M' | 'F'`): 音色的性别 **age** (`'Young' | 'Middle' | 'Old'`): 音色的年龄类别 **style** (`'Conversational' | 'Narrative'`): 音色的说话风格 **voiceId** (`string`): 音色的唯一标识符 ### `listen()` PlayAI 不支持此方法,调用时会抛出错误。PlayAI 不提供语音转文本功能。 ## 注意事项 - PlayAI 身份验证同时需要 API key 和 user ID - 该服务提供两个模型:'PlayDialog' 和 'Play3.0-mini' - 每种音色都有唯一的 S3 manifest ID,进行 API 调用时必须使用该 ID