Skip to main content

Deepgram

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

🌐 The Deepgram voice implementation in Mastra provides text-to-speech (TTS) and speech-to-text (STT) capabilities using Deepgram's API. It supports multiple voice models and languages, with configurable options for both speech synthesis and transcription.

使用示例
Direct link to 使用示例

🌐 Usage Example

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);

构造函数参数
Direct link to 构造函数参数

🌐 Constructor Parameters

speechModel?:

DeepgramVoiceConfig
= { name: 'aura' }
Configuration for text-to-speech functionality.

listeningModel?:

DeepgramVoiceConfig
= { name: 'nova' }
Configuration for speech-to-text functionality.

speaker?:

DeepgramVoiceId
= 'asteria-en'
Default voice to use for text-to-speech

DeepgramVoiceConfig
Direct link to DeepgramVoiceConfig

name?:

DeepgramModel
The Deepgram model to use

apiKey?:

string
Deepgram API key. Falls back to DEEPGRAM_API_KEY environment variable

properties?:

Record<string, any>
Additional properties to pass to the Deepgram API

language?:

string
Language code for the model

方法
Direct link to 方法

🌐 Methods

speak()
Direct link to speak()

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

🌐 Converts text to speech using the configured speech model and voice.

input:

string | NodeJS.ReadableStream
Text to convert to speech. If a stream is provided, it will be converted to text first.

options?:

object
Additional options for speech synthesis

options.speaker?:

string
Override the default speaker for this request

返回:Promise<NodeJS.ReadableStream>

🌐 Returns: Promise<NodeJS.ReadableStream>

listen()
Direct link to listen()

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

🌐 Converts speech to text using the configured listening model.

audioStream:

NodeJS.ReadableStream
Audio stream to transcribe

options?:

object
Additional options to pass to the Deepgram API

返回:Promise<string>

🌐 Returns: Promise<string>

getSpeakers()
Direct link to getSpeakers()

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

🌐 Returns a list of available voice options.

voiceId:

string
Unique identifier for the voice