メインコンテンツへ移動

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 について返すメタデータが異なります。

voiceId:

string
Voice の一意な識別子(例:'alloy'、'echo'、'fable'、'onyx'、'nova'、'shimmer')

注意事項
注意事項への直接リンク

  • 使用可能な Voice は Provider によって大きく異なります
  • Voice の完全な一覧を取得するために認証が必要な Provider もあります
  • Provider がこのメソッドをサポートしない場合、デフォルト実装は空の配列を返します
  • 一覧を頻繁に表示する場合は、パフォーマンスのために結果のキャッシュを検討してください
  • voiceId プロパティはすべての Provider で必ず存在しますが、追加のメタデータは異なります