ElevenLabs
Mastra 中的 ElevenLabs 语音实现使用 ElevenLabs API 提供高质量的文本转语音(TTS)和语音转文本(STT)功能。
🌐 The ElevenLabs voice implementation in Mastra provides high-quality text-to-speech (TTS) and speech-to-text (STT) capabilities using the ElevenLabs API.
使用示例Direct link to 使用示例
🌐 Usage Example
import { ElevenLabsVoice } from "@mastra/voice-elevenlabs";
// Initialize with default configuration (uses ELEVENLABS_API_KEY environment variable)
const voice = new ElevenLabsVoice();
// Initialize with custom configuration
const voice = new ElevenLabsVoice({
speechModel: {
name: "eleven_multilingual_v2",
apiKey: "your-api-key",
},
speaker: "custom-speaker-id",
});
// Text-to-Speech
const audioStream = await voice.speak("Hello, world!");
// Get available speakers
const speakers = await voice.getSpeakers();
构造函数参数Direct link to 构造函数参数
🌐 Constructor Parameters
speechModel?:
speaker?:
ElevenLabsVoiceConfigDirect link to ElevenLabsVoiceConfig
name?:
apiKey?:
方法Direct link to 方法
🌐 Methods
speak()Direct link to speak()
使用配置的语音模型和声音将文本转换为语音。
🌐 Converts text to speech using the configured speech model and voice.
input:
options?:
options.speaker?:
返回:Promise<NodeJS.ReadableStream>
🌐 Returns: Promise<NodeJS.ReadableStream>
getSpeakers()Direct link to getSpeakers()
返回一个可用语音选项的数组,每个节点包含:
🌐 Returns an array of available voice options, where each node contains:
voiceId:
name:
language:
gender:
listen()Direct link to listen()
使用 ElevenLabs 语音转文本 API 将音频输入转换为文本。
🌐 Converts audio input to text using ElevenLabs Speech-to-Text API.
input:
options?:
options 对象支持以下属性:
🌐 The options object supports the following properties:
language_code?:
tag_audio_events?:
num_speakers?:
filetype?:
timeoutInSeconds?:
maxRetries?:
abortSignal?:
返回:Promise<string> - 一个解析为转录文本的 Promise
🌐 Returns: Promise<string> - A Promise that resolves to the transcribed text
重要提示Direct link to 重要提示
🌐 Important Notes
- 需要 ElevenLabs API 密钥。可以通过
ELEVENLABS_API_KEY环境变量设置,或在构造函数中传入。 - 默认扬声器设置为 Aria(ID:'9BWtsMINqrJLrRacOk9x')。
- ElevenLabs 不支持语音转文字功能。
- 可以使用
getSpeakers()方法检索可用的语音,该方法返回每个语音的详细信息,包括语言和性别。