跳到主要内容

Deepgram

Mastra 中的 Deepgram Voice 实现使用 Deepgram API 提供文本转语音 (TTS) 和语音转文本 (STT) 功能。它支持多种语音模型和语言,并为语音合成和转录提供可配置选项。

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

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

name?:

DeepgramModel
要使用的 Deepgram 模型

apiKey?:

string
Deepgram API 密钥。未提供时使用 DEEPGRAM_API_KEY 环境变量

properties?:

Record<string, any>
要传递给 Deepgram API 的其他属性

language?:

string
模型的语言代码

listeningModel?:

DeepgramVoiceConfig
= { name: 'nova' }
语音转文本功能的配置。
DeepgramVoiceConfig

name?:

DeepgramModel
要使用的 Deepgram 模型

apiKey?:

string
Deepgram API 密钥。未提供时使用 DEEPGRAM_API_KEY 环境变量

properties?:

Record<string, any>
要传递给 Deepgram API 的其他属性

language?:

string
模型的语言代码

speaker?:

DeepgramVoiceId
= 'asteria-en'
文本转语音使用的默认声音

方法
方法的直接链接

speak()
speak的直接链接

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

input:

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

options?:

object
语音合成的其他选项
object

speaker?:

string
为此次请求覆盖默认 speaker

返回:Promise<NodeJS.ReadableStream>

listen()
listen的直接链接

使用配置的听写模型将语音转换为文本。

audioStream:

NodeJS.ReadableStream
要转录的音频流

options?:

object
要传递给 Deepgram API 的其他选项

返回:Promise<string>

getSpeakers()
getspeakers的直接链接

返回可用的声音选项列表。

voiceId:

string
声音的唯一标识符