> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # Deepgram Mastra 中的 Deepgram Voice 实现使用 Deepgram API 提供文本转语音 (TTS) 和语音转文本 (STT) 功能。它支持多种语音模型和语言,并为语音合成和转录提供可配置选项。 ## 使用示例 ```typescript import { DeepgramVoice } from '@mastra/voice-deepgram' // Initialize with default configuration (uses DEEPGRAM_API_KEY environment variable) const voice = new DeepgramVoice() // Initialize with custom configuration const voice = new DeepgramVoice({ speechModel: { name: 'aura', apiKey: 'your-api-key', }, listeningModel: { name: 'nova-2', apiKey: 'your-api-key', }, speaker: 'asteria-en', }) // Text-to-Speech const audioStream = await voice.speak('Hello, world!') // Speech-to-Text const transcript = await voice.listen(audioStream) ``` ## 构造函数参数 **speechModel** (`DeepgramVoiceConfig`): 文本转语音功能的配置。 (Default: `{ name: 'aura' }`) **speechModel.name** (`DeepgramModel`): 要使用的 Deepgram 模型 **speechModel.apiKey** (`string`): Deepgram API 密钥。未提供时使用 DEEPGRAM\_API\_KEY 环境变量 **speechModel.properties** (`Record`): 要传递给 Deepgram API 的其他属性 **speechModel.language** (`string`): 模型的语言代码 **listeningModel** (`DeepgramVoiceConfig`): 语音转文本功能的配置。 (Default: `{ name: 'nova' }`) **listeningModel.name** (`DeepgramModel`): 要使用的 Deepgram 模型 **listeningModel.apiKey** (`string`): Deepgram API 密钥。未提供时使用 DEEPGRAM\_API\_KEY 环境变量 **listeningModel.properties** (`Record`): 要传递给 Deepgram API 的其他属性 **listeningModel.language** (`string`): 模型的语言代码 **speaker** (`DeepgramVoiceId`): 文本转语音使用的默认声音 (Default: `'asteria-en'`) ## 方法 ### `speak()` 使用配置的语音模型和声音将文本转换为语音。 **input** (`string | NodeJS.ReadableStream`): 要转换为语音的文本。如果提供流,则先将其转换为文本。 **options** (`object`): 语音合成的其他选项 **options.speaker** (`string`): 为此次请求覆盖默认 speaker 返回:`Promise` ### `listen()` 使用配置的听写模型将语音转换为文本。 **audioStream** (`NodeJS.ReadableStream`): 要转录的音频流 **options** (`object`): 要传递给 Deepgram API 的其他选项 返回:`Promise` ### `getSpeakers()` 返回可用的声音选项列表。 **voiceId** (`string`): 声音的唯一标识符