voice.getSpeakers()
getSpeakers() メソッドは、Voice Provider から使用可能な Voice オプション(Speaker)の一覧を取得します。アプリケーションはユーザーに Voice の選択肢を提示したり、コンテキストに最適な Voice をプログラムで選択したりできます。
使用例使用例への直接リンク
import { OpenAIVoice } from '@mastra/voice-openai'
import { ElevenLabsVoice } from '@mastra/voice-elevenlabs'
// Initialize voice providers
const openaiVoice = new OpenAIVoice()
const elevenLabsVoice = new ElevenLabsVoice({
apiKey: process.env.ELEVENLABS_API_KEY,
})
// Get available speakers from OpenAI
const openaiSpeakers = await openaiVoice.getSpeakers()
console.log('OpenAI voices:', openaiSpeakers)
// Example output: [{ voiceId: "alloy" }, { voiceId: "echo" }, { voiceId: "fable" }, ...]
// Get available speakers from ElevenLabs
const elevenLabsSpeakers = await elevenLabsVoice.getSpeakers()
console.log('ElevenLabs voices:', elevenLabsSpeakers)
// Example output: [{ voiceId: "21m00Tcm4TlvDq8ikWAM", name: "Rachel" }, ...]
// Use a specific voice for speech
const text = 'Hello, this is a test of different voices.'
await openaiVoice.speak(text, { speaker: openaiSpeakers[2].voiceId })
await elevenLabsVoice.speak(text, { speaker: elevenLabsSpeakers[0].voiceId })
パラメーターパラメーターへの直接リンク
このメソッドはパラメーターを受け取りません。
戻り値戻り値への直接リンク
Promise<Array<{ voiceId: string } & TSpeakerMetadata>>:
Promise
Voice オプションの配列に解決する Promise。各オプションには少なくとも voiceId プロパティが含まれ、Provider 固有の追加メタデータが含まれる場合があります。
Provider 固有のメタデータProvider 固有のメタデータへの直接リンク
Voice Provider ごとに、Voice について返すメタデータが異なります。
- OpenAI
- OpenAI Realtime
- Deepgram
- ElevenLabs
- Azure
- Murf
- PlayAI
- Speechify
- Sarvam
voiceId:
string
Voice の一意な識別子(例:'alloy'、'echo'、'fable'、'onyx'、'nova'、'shimmer')
voiceId:
string
Voice の一意な識別子(例:'alloy'、'echo'、'fable'、'onyx'、'nova'、'shimmer')
voiceId:
string
Voice の一意な識別子
language:
string
Voice ID に含まれる言語コード(例:'en')
voiceId:
string
Voice の一意な識別子
name:
string
人が読める Voice 名
category:
string
Voice のカテゴリー(例:'premade'、'cloned')
voiceId:
string
Voice の一意な識別子
languageCodes:
string[]
Voice がサポートする言語コードの配列(例:['en-US'])
voiceId:
string
Voice の一意な識別子
language:
string
Voice ID から抽出された言語コード(例:'en')
region:
string
Voice ID から抽出されたリージョンコード(例:'US')
voiceId:
string
Voice の一意な識別子
name:
string
Voice 名(voiceId と同じ)
language:
string
Voice ID から抽出された言語コード(例:'en')
gender:
string
Voice の性別(現在の実装では常に 'neutral')
voiceId:
string
Voice の一意な識別子(manifest.json の S3 URL)
name:
string
人が読める Voice 名(例:'Angelo'、'Arsenio')
accent:
string
Voice のアクセント(例:'US'、'Irish'、'US African American')
gender:
string
Voice の性別('M' または 'F')
age:
string
Voice の年齢カテゴリー(例:'Young'、'Middle')
style:
string
Voice の発話スタイル(例:'Conversational')
voiceId:
string
Voice の一意な識別子
name:
string
人が読める Voice 名
language:
string
Voice の言語コード(例:'en-US')
voiceId:
string
Voice の一意な識別子
name:
string
人が読める Voice 名
language:
string
Voice の言語(例:'english'、'hindi')
gender:
string
Voice の性別('male' または 'female')
注意事項注意事項への直接リンク
- 使用可能な Voice は Provider によって大きく異なります
- Voice の完全な一覧を取得するために認証が必要な Provider もあります
- Provider がこのメソッドをサポートしない場合、デフォルト実装は空の配列を返します
- 一覧を頻繁に表示する場合は、パフォーマンスのために結果のキャッシュを検討してください
voiceIdプロパティはすべての Provider で必ず存在しますが、追加のメタデータは異なります