> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # Deepgram Mastra 的 Deepgram 語音實作使用 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`): 聲音的唯一識別碼