跳至主要內容

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
針對此請求覆寫預設語音

回傳:Promise<NodeJS.ReadableStream>

listen()
「listen」的直接連結

使用已設定的聆聽模型,將語音轉換為文字。

audioStream:

NodeJS.ReadableStream
要轉錄的音訊資料流

options?:

object
要傳遞給 Deepgram API 的其他選項

回傳:Promise<string>

getSpeakers()
「getspeakers」的直接連結

回傳可用的語音選項清單。

voiceId:

string
語音的唯一識別碼