> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # Speechify Mastra 的 Speechify 語音實作透過 Speechify API 提供文字轉語音功能。 ## 用法範例 ```typescript import { SpeechifyVoice } from '@mastra/voice-speechify' // Initialize with default configuration (uses SPEECHIFY_API_KEY environment variable) const voice = new SpeechifyVoice() // Initialize with custom configuration const voice = new SpeechifyVoice({ speechModel: { name: 'simba-3.2', apiKey: 'your-api-key', }, speaker: 'harper_32', // Default voice (simba-3.2 serves the curated Simba 3 voices only) }) // Convert text to speech const audioStream = await voice.speak('Hello, world!', { speaker: 'imogen_32', // Override default voice }) ``` ## 建構函式參數 **speechModel** (`SpeechifyConfig`): 文字轉語音功能的設定 (Default: `{ name: 'simba-english' }`) **speechModel.name** (`SpeechifyModel`): 要使用的 Speechify 模型('simba-3.2'、'simba-3.0'、'simba-english' 或 'simba-multilingual') **speechModel.apiKey** (`string`): Speechify API 金鑰。若未提供,則使用 SPEECHIFY\_API\_KEY 環境變數 **speaker** (`SpeechifyVoiceId`): 語音合成所使用的預設語音 ID。Simba 3 模型只提供精選語音集(harper\_32、imogen\_32 等);傳統目錄中的語音(george、henry 等)適用於 simba-english 與 simba-multilingual (Default: `Simba 3 模型為 'harper_32',其他模型則為 'george'`) ## 方法 ### `speak()` 使用設定的語音模型與語音,將文字轉換成語音。 **input** (`string | NodeJS.ReadableStream`): 要轉換成語音的文字。若提供串流,會先將其轉換成文字。 **options** (`Options`): 設定選項。 **options.speaker** (`string`): 覆寫這次請求的預設 speaker **options.model** (`SpeechifyModel`): 覆寫這次請求的預設模型 回傳:`Promise` ### `getSpeakers()` 回傳可用語音選項的陣列,其中每個節點包含: **voiceId** (`string`): 語音的唯一識別碼 **name** (`string`): 語音的顯示名稱 **language** (`string`): 語音的語言程式碼 **gender** (`string`): 語音的性別 ### `listen()` Speechify 不支援此方法,呼叫時會擲回錯誤。Speechify 不提供語音轉文字功能。 ## 注意事項 - Speechify 驗證需要 API 金鑰 - 預設模型為 'simba-english' - 'simba-3.2' 是 Speechify 最新的串流模型,具有最低延遲與最豐富的表現力,也是英文的建議模型 - 'simba-3.2' 與 'simba-3.0' 目前僅支援英文;非英文或混合語言輸入請使用 'simba-multilingual' - 'simba-3.2' 與 'simba-3.0' 只提供精選語音集:'beatrice\_32'、'dominic\_32'、'edmund\_32'、'geffen\_32'、'harper\_32'、'hugh\_32'、'imogen\_32'、'wyatt\_32'。在這些模型上使用 'george' 等傳統目錄語音會回傳錯誤 - 預設 speaker 取決於設定的模型:Simba 3 模型為 'harper\_32',其他模型則為 'george' - 不支援語音轉文字功能 - 可透過 speak() 方法的 options 參數傳入其他音訊串流選項