跳至主要內容

Deepgram

Mastra 的 Deepgram 語音實作使用 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
聲音的唯一識別碼