跳到主要内容

PlayAI

Mastra 中的 PlayAI 语音实现通过 PlayAI API 提供文本转语音功能。

使用示例
使用示例的直接链接

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
= { name: 'PlayDialog' }
文本转语音功能的配置
PlayAIConfig

name?:

'PlayDialog' | 'Play3.0-mini'
要使用的 PlayAI 模型

apiKey?:

string
PlayAI API key。未设置时使用 PLAYAI_API_KEY 环境变量

userId?:

string
PlayAI user ID。未设置时使用 PLAYAI_USER_ID 环境变量

speaker?:

string
= 第一个可用的音色 ID
用于语音合成的默认音色 ID

方法
方法的直接链接

speak()
speak的直接链接

使用已配置的语音模型和音色将文本转换为语音。

input:

string | NodeJS.ReadableStream
要转换为语音的文本。如果提供流,会先将其转换为文本。

options?:

Options
配置选项。
Options

speaker?:

string
为本次请求覆盖默认 speaker

返回:Promise<NodeJS.ReadableStream>

getSpeakers()
getspeakers的直接链接

返回可用音色选项的数组,其中每个节点包含:

name:

string
音色名称

accent:

string
音色的口音(例如 'US'、'British'、'Australian')

gender:

'M' | 'F'
音色的性别

age:

'Young' | 'Middle' | 'Old'
音色的年龄类别

style:

'Conversational' | 'Narrative'
音色的说话风格

voiceId:

string
音色的唯一标识符

listen()
listen的直接链接

PlayAI 不支持此方法,调用时会抛出错误。PlayAI 不提供语音转文本功能。

注意事项
注意事项的直接链接

  • PlayAI 身份验证同时需要 API key 和 user ID
  • 该服务提供两个模型:'PlayDialog' 和 'Play3.0-mini'
  • 每种音色都有唯一的 S3 manifest ID,进行 API 调用时必须使用该 ID