> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/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`): 針對此請求覆寫預設語音 回傳:`Promise` ### `listen()` 使用已設定的聆聽模型,將語音轉換為文字。 **audioStream** (`NodeJS.ReadableStream`): 要轉錄的音訊資料流 **options** (`object`): 要傳遞給 Deepgram API 的其他選項 回傳:`Promise` ### `getSpeakers()` 回傳可用的語音選項清單。 **voiceId** (`string`): 語音的唯一識別碼