> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # Mastra の Voice Mastra の Voice システムは音声対話のための統一インターフェースを提供し、アプリケーションで Text-to-Speech(TTS)、Speech-to-Text(STT)、リアルタイムの Speech-to-Speech(STS)を利用できるようにします。 ## Agent に Voice を追加する `voice` プロパティで Voice Provider を Agent に渡します。設定する Provider に応じて、同じプロパティで Text-to-Speech(TTS)、Speech-to-Text(STT)、リアルタイムの Speech-to-Speech(STS)を利用できます。 ```typescript import { Agent } from '@mastra/core/agent' import { OpenAIVoice } from '@mastra/voice-openai' // Initialize OpenAI voice for TTS const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new OpenAIVoice(), }) ``` これにより、次の Voice 機能を使用できます。 ### Text-to-Speech(TTS) Mastra の TTS 機能を使って、Agent の回答を自然な音声に変換します。 OpenAI や ElevenLabs など、複数の Provider から選択できます。 詳しい設定オプションと高度な機能については、[Text-to-Speech ガイド](https://mastra.zisheng.pro/ja/guides/voice/text-to-speech)を参照してください。 **OpenAI**: ```typescript import { Agent } from '@mastra/core/agent' import { OpenAIVoice } from '@mastra/voice-openai' import { playAudio } from '@mastra/node-audio' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new OpenAIVoice(), }) const { text } = await voiceAgent.generate('What color is the sky?') // Convert text to speech to an Audio Stream const audioStream = await voiceAgent.voice.speak(text, { speaker: 'default', // Optional: specify a speaker responseFormat: 'wav', // Optional: specify a response format }) playAudio(audioStream) ``` OpenAI Voice Provider の詳細については、[OpenAI Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/openai)を参照してください。 **Azure**: ```typescript import { Agent } from '@mastra/core/agent' import { AzureVoice } from '@mastra/voice-azure' import { playAudio } from '@mastra/node-audio' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new AzureVoice(), }) const { text } = await voiceAgent.generate('What color is the sky?') // Convert text to speech to an Audio Stream const audioStream = await voiceAgent.voice.speak(text, { speaker: 'en-US-JennyNeural', // Optional: specify a speaker }) playAudio(audioStream) ``` Azure Voice Provider の詳細については、[Azure Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/azure)を参照してください。 **ElevenLabs**: ```typescript import { Agent } from '@mastra/core/agent' import { ElevenLabsVoice } from '@mastra/voice-elevenlabs' import { playAudio } from '@mastra/node-audio' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new ElevenLabsVoice(), }) const { text } = await voiceAgent.generate('What color is the sky?') // Convert text to speech to an Audio Stream const audioStream = await voiceAgent.voice.speak(text, { speaker: 'default', // Optional: specify a speaker }) playAudio(audioStream) ``` ElevenLabs Voice Provider の詳細については、[ElevenLabs Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/elevenlabs)を参照してください。 **PlayAI**: ```typescript import { Agent } from '@mastra/core/agent' import { PlayAIVoice } from '@mastra/voice-playai' import { playAudio } from '@mastra/node-audio' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new PlayAIVoice(), }) const { text } = await voiceAgent.generate('What color is the sky?') // Convert text to speech to an Audio Stream const audioStream = await voiceAgent.voice.speak(text, { speaker: 'default', // Optional: specify a speaker }) playAudio(audioStream) ``` PlayAI Voice Provider の詳細については、[PlayAI Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/playai)を参照してください。 **Google**: ```typescript import { Agent } from '@mastra/core/agent' import { GoogleVoice } from '@mastra/voice-google' import { playAudio } from '@mastra/node-audio' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new GoogleVoice(), }) const { text } = await voiceAgent.generate('What color is the sky?') // Convert text to speech to an Audio Stream const audioStream = await voiceAgent.voice.speak(text, { speaker: 'en-US-Studio-O', // Optional: specify a speaker }) playAudio(audioStream) ``` Google Voice Provider の詳細については、[Google Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/google)を参照してください。 **Cloudflare**: ```typescript import { Agent } from '@mastra/core/agent' import { CloudflareVoice } from '@mastra/voice-cloudflare' import { playAudio } from '@mastra/node-audio' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new CloudflareVoice(), }) const { text } = await voiceAgent.generate('What color is the sky?') // Convert text to speech to an Audio Stream const audioStream = await voiceAgent.voice.speak(text, { speaker: 'default', // Optional: specify a speaker }) playAudio(audioStream) ``` Cloudflare Voice Provider の詳細については、[Cloudflare Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/cloudflare)を参照してください。 **Deepgram**: ```typescript import { Agent } from '@mastra/core/agent' import { DeepgramVoice } from '@mastra/voice-deepgram' import { playAudio } from '@mastra/node-audio' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new DeepgramVoice(), }) const { text } = await voiceAgent.generate('What color is the sky?') // Convert text to speech to an Audio Stream const audioStream = await voiceAgent.voice.speak(text, { speaker: 'aura-english-us', // Optional: specify a speaker }) playAudio(audioStream) ``` Deepgram Voice Provider の詳細については、[Deepgram Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/deepgram)を参照してください。 **Inworld**: ```typescript import { Agent } from '@mastra/core/agent' import { InworldVoice } from '@mastra/voice-inworld' import { playAudio } from '@mastra/node-audio' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new InworldVoice(), }) const { text } = await voiceAgent.generate('What color is the sky?') // Convert text to speech to an Audio Stream const audioStream = await voiceAgent.voice.speak(text, { speaker: 'Dennis', // Optional: specify a speaker }) playAudio(audioStream) ``` Inworld Voice Provider の詳細については、[Inworld Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/inworld)を参照してください。 **Speechify**: ```typescript import { Agent } from '@mastra/core/agent' import { SpeechifyVoice } from '@mastra/voice-speechify' import { playAudio } from '@mastra/node-audio' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new SpeechifyVoice(), }) const { text } = await voiceAgent.generate('What color is the sky?') // Convert text to speech to an Audio Stream const audioStream = await voiceAgent.voice.speak(text, { speaker: 'matthew', // Optional: specify a speaker }) playAudio(audioStream) ``` Speechify Voice Provider の詳細については、[Speechify Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/speechify)を参照してください。 **Sarvam**: ```typescript import { Agent } from '@mastra/core/agent' import { SarvamVoice } from '@mastra/voice-sarvam' import { playAudio } from '@mastra/node-audio' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new SarvamVoice(), }) const { text } = await voiceAgent.generate('What color is the sky?') // Convert text to speech to an Audio Stream const audioStream = await voiceAgent.voice.speak(text, { speaker: 'shubh', // Optional: specify a bulbul:v3 speaker }) playAudio(audioStream) ``` Sarvam Voice Provider の詳細については、[Sarvam Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/sarvam)を参照してください。 **Murf**: ```typescript import { Agent } from '@mastra/core/agent' import { MurfVoice } from '@mastra/voice-murf' import { playAudio } from '@mastra/node-audio' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new MurfVoice(), }) const { text } = await voiceAgent.generate('What color is the sky?') // Convert text to speech to an Audio Stream const audioStream = await voiceAgent.voice.speak(text, { speaker: 'default', // Optional: specify a speaker }) playAudio(audioStream) ``` Murf Voice Provider の詳細については、[Murf Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/murf)を参照してください。 ### Speech-to-Text(STT) OpenAI や ElevenLabs などの Provider を使って音声コンテンツを文字起こしします。詳しい設定オプションについては、[Speech-to-Text](https://mastra.zisheng.pro/ja/guides/voice/speech-to-text)を参照してください。 サンプル音声ファイルは[こちら](https://github.com/mastra-ai/realtime-voice-demo/raw/refs/heads/main/how_can_i_help_you.mp3)からダウンロードできます。 [](https://github.com/mastra-ai/realtime-voice-demo/raw/refs/heads/main/how_can_i_help_you.mp3) **OpenAI**: ```typescript import { Agent } from '@mastra/core/agent' import { OpenAIVoice } from '@mastra/voice-openai' import { createReadStream } from 'fs' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new OpenAIVoice(), }) // Use an audio file from a URL const audioStream = await createReadStream('./how_can_i_help_you.mp3') // Convert audio to text const transcript = await voiceAgent.voice.listen(audioStream) console.log(`User said: ${transcript}`) // Generate a response based on the transcript const { text } = await voiceAgent.generate(transcript) ``` OpenAI Voice Provider の詳細については、[OpenAI Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/openai)を参照してください。 **Azure**: ```typescript import { createReadStream } from 'fs' import { Agent } from '@mastra/core/agent' import { AzureVoice } from '@mastra/voice-azure' import { createReadStream } from 'fs' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new AzureVoice(), }) // Use an audio file from a URL const audioStream = await createReadStream('./how_can_i_help_you.mp3') // Convert audio to text const transcript = await voiceAgent.voice.listen(audioStream) console.log(`User said: ${transcript}`) // Generate a response based on the transcript const { text } = await voiceAgent.generate(transcript) ``` Azure Voice Provider の詳細については、[Azure Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/azure)を参照してください。 **ElevenLabs**: ```typescript import { Agent } from '@mastra/core/agent' import { ElevenLabsVoice } from '@mastra/voice-elevenlabs' import { createReadStream } from 'fs' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new ElevenLabsVoice(), }) // Use an audio file from a URL const audioStream = await createReadStream('./how_can_i_help_you.mp3') // Convert audio to text const transcript = await voiceAgent.voice.listen(audioStream) console.log(`User said: ${transcript}`) // Generate a response based on the transcript const { text } = await voiceAgent.generate(transcript) ``` ElevenLabs Voice Provider の詳細については、[ElevenLabs Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/elevenlabs)を参照してください。 **Google**: ```typescript import { Agent } from '@mastra/core/agent' import { GoogleVoice } from '@mastra/voice-google' import { createReadStream } from 'fs' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new GoogleVoice(), }) // Use an audio file from a URL const audioStream = await createReadStream('./how_can_i_help_you.mp3') // Convert audio to text const transcript = await voiceAgent.voice.listen(audioStream) console.log(`User said: ${transcript}`) // Generate a response based on the transcript const { text } = await voiceAgent.generate(transcript) ``` Google Voice Provider の詳細については、[Google Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/google)を参照してください。 **Cloudflare**: ```typescript import { Agent } from '@mastra/core/agent' import { CloudflareVoice } from '@mastra/voice-cloudflare' import { createReadStream } from 'fs' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new CloudflareVoice(), }) // Use an audio file from a URL const audioStream = await createReadStream('./how_can_i_help_you.mp3') // Convert audio to text const transcript = await voiceAgent.voice.listen(audioStream) console.log(`User said: ${transcript}`) // Generate a response based on the transcript const { text } = await voiceAgent.generate(transcript) ``` Cloudflare Voice Provider の詳細については、[Cloudflare Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/cloudflare)を参照してください。 **Deepgram**: ```typescript import { Agent } from '@mastra/core/agent' import { DeepgramVoice } from '@mastra/voice-deepgram' import { createReadStream } from 'fs' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new DeepgramVoice(), }) // Use an audio file from a URL const audioStream = await createReadStream('./how_can_i_help_you.mp3') // Convert audio to text const transcript = await voiceAgent.voice.listen(audioStream) console.log(`User said: ${transcript}`) // Generate a response based on the transcript const { text } = await voiceAgent.generate(transcript) ``` Deepgram Voice Provider の詳細については、[Deepgram Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/deepgram)を参照してください。 **Inworld**: ```typescript import { Agent } from '@mastra/core/agent' import { InworldVoice } from '@mastra/voice-inworld' import { createReadStream } from 'fs' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new InworldVoice(), }) // Use an audio file from a URL const audioStream = await createReadStream('./how_can_i_help_you.mp3') // Convert audio to text const transcript = await voiceAgent.voice.listen(audioStream) console.log(`User said: ${transcript}`) // Generate a response based on the transcript const { text } = await voiceAgent.generate(transcript) ``` Inworld Voice Provider の詳細については、[Inworld Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/inworld)を参照してください。 **Sarvam**: ```typescript import { Agent } from '@mastra/core/agent' import { SarvamVoice } from '@mastra/voice-sarvam' import { createReadStream } from 'fs' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new SarvamVoice(), }) // Use an audio file from a URL const audioStream = await createReadStream('./how_can_i_help_you.mp3') // Convert audio to text const transcript = await voiceAgent.voice.listen(audioStream) console.log(`User said: ${transcript}`) // Generate a response based on the transcript const { text } = await voiceAgent.generate(transcript) ``` Sarvam Voice Provider の詳細については、[Sarvam Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/sarvam)を参照してください。 ### Speech-to-Speech(STS) Speech-to-Speech 機能で会話体験を構築します。統一 API により、ユーザーと AI Agent 間のリアルタイム音声対話が可能になります。 詳しい設定オプションと高度な機能については、[Speech-to-Speech](https://mastra.zisheng.pro/ja/guides/voice/speech-to-speech)を参照してください。 **OpenAI**: ```typescript import { Agent } from '@mastra/core/agent' import { playAudio, getMicrophoneStream } from '@mastra/node-audio' import { OpenAIRealtimeVoice } from '@mastra/voice-openai-realtime' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new OpenAIRealtimeVoice(), }) // Listen for agent audio responses voiceAgent.voice.on('speaker', ({ audio }) => { playAudio(audio) }) // Initiate the conversation await voiceAgent.voice.speak('How can I help you today?') // Send continuous audio from the microphone const micStream = getMicrophoneStream() await voiceAgent.voice.send(micStream) ``` OpenAI Voice Provider の詳細については、[OpenAI Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/openai-realtime)を参照してください。 **Google**: ```typescript import { Agent } from '@mastra/core/agent' import { playAudio, getMicrophoneStream } from '@mastra/node-audio' import { GeminiLiveVoice } from '@mastra/voice-google-gemini-live' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new GeminiLiveVoice({ // Live API mode apiKey: process.env.GOOGLE_API_KEY, model: 'gemini-2.0-flash-exp', speaker: 'Puck', debug: true, // Vertex AI alternative: // vertexAI: true, // project: 'your-gcp-project', // location: 'us-central1', // serviceAccountKeyFile: '/path/to/service-account.json', }), }) // Connect before using speak/send await voiceAgent.voice.connect() // Listen for agent audio responses voiceAgent.voice.on('speaker', ({ audio }) => { playAudio(audio) }) // Listen for text responses and transcriptions voiceAgent.voice.on('writing', ({ text, role }) => { console.log(`${role}: ${text}`) }) // Initiate the conversation await voiceAgent.voice.speak('How can I help you today?') // Send continuous audio from the microphone const micStream = getMicrophoneStream() await voiceAgent.voice.send(micStream) ``` Google Gemini Live Voice Provider の詳細については、[Google Gemini Live リファレンス](https://mastra.zisheng.pro/ja/reference/voice/google-gemini-live)を参照してください。 **AWS Nova Sonic**: ```typescript import { Agent } from '@mastra/core/agent' import { playAudio, getMicrophoneStream } from '@mastra/node-audio' import { NovaSonicVoice } from '@mastra/voice-aws-nova-sonic' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new NovaSonicVoice({ region: 'us-east-1', speaker: 'matthew', // Static credentials are optional. The default AWS credential // provider chain is used when none are passed. }), }) // Connect before using speak/send await voiceAgent.voice.connect() // Listen for assistant audio (Int16Array PCM) voiceAgent.voice.on('speaking', ({ audioData }) => { if (audioData) playAudio(audioData) }) // Listen for transcribed text voiceAgent.voice.on('writing', ({ text, role }) => { console.log(`${role}: ${text}`) }) // Initiate the conversation await voiceAgent.voice.speak('How can I help you today?') // Send continuous audio from the microphone const micStream = getMicrophoneStream() await voiceAgent.voice.send(micStream) ``` AWS Nova Sonic Voice Provider の詳細については、[AWS Nova Sonic リファレンス](https://mastra.zisheng.pro/ja/reference/voice/aws-nova-sonic)を参照してください。 **Inworld Realtime**: ```typescript import { Agent } from '@mastra/core/agent' import { playAudio, getMicrophoneStream } from '@mastra/node-audio' import { InworldRealtimeVoice } from '@mastra/voice-inworld' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'openai/gpt-5.6-sol', voice: new InworldRealtimeVoice({ apiKey: process.env.INWORLD_API_KEY, model: 'inworld/models/gemma-4-26b-a4b-it', speaker: 'Sarah', }), }) // Connect before using speak/send await voiceAgent.voice.connect() // Listen for agent audio (PCM stream) voiceAgent.voice.on('speaker', stream => { playAudio(stream) }) // Listen for text responses and transcriptions voiceAgent.voice.on('writing', ({ text, role }) => { console.log(`${role}: ${text}`) }) // Initiate the conversation await voiceAgent.voice.speak('How can I help you today?') // Send continuous audio from the microphone const micStream = getMicrophoneStream() await voiceAgent.voice.send(micStream) ``` Inworld Realtime Voice Provider の詳細については、[Inworld Realtime リファレンス](https://mastra.zisheng.pro/ja/reference/voice/inworld-realtime)を参照してください。 **xAI**: ```typescript import { Agent } from '@mastra/core/agent' import { playAudio, getMicrophoneStream } from '@mastra/node-audio' import { XAIRealtimeVoice } from '@mastra/voice-xai-realtime' const voiceAgent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that can help users with their tasks.', model: 'xai/grok-4.3', voice: new XAIRealtimeVoice({ apiKey: process.env.XAI_API_KEY, model: 'grok-voice-think-fast-1.0', speaker: 'eve', turnDetection: { type: 'server_vad' }, }), }) // Connect before using speak/send await voiceAgent.voice.connect() // Listen for agent audio responses voiceAgent.voice.on('speaker', audioStream => { playAudio(audioStream) }) // Listen for text responses and transcriptions voiceAgent.voice.on('writing', ({ text, role }) => { console.log(`${role}: ${text}`) }) // Initiate the conversation await voiceAgent.voice.speak('How can I help you today?') // Send continuous audio from the microphone const micStream = getMicrophoneStream() await voiceAgent.voice.send(micStream) ``` xAI Voice Provider の詳細については、[xAI Realtime Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/xai-realtime)を参照してください。 ### リアルタイム Voice ブラウザまたは電話で、ユーザーが割り込んで話せるライブ通話を実行します。Mastra は音声ループを LiveKit に任せ、音声区間検出、意味に基づくターン検出、割り込みを処理します。一方、Agent は独自のモデル、Tools、Memory を使って各応答を生成します。セットアップと設定オプションについては、[リアルタイム Voice](https://mastra.zisheng.pro/ja/guides/voice/realtime-voice)を参照してください。 ## Voice の設定 各 Voice Provider には、異なるモデルとオプションを設定できます。サポートするすべての Provider の詳しい設定オプションを次に示します。 **OpenAI**: ```typescript // OpenAI Voice Configuration const voice = new OpenAIVoice({ speechModel: { name: 'gpt-3.5-turbo', // Example model name apiKey: process.env.OPENAI_API_KEY, language: 'en-US', // Language code voiceType: 'neural', // Type of voice model }, listeningModel: { name: 'whisper-1', // Example model name apiKey: process.env.OPENAI_API_KEY, language: 'en-US', // Language code format: 'wav', // Audio format }, speaker: 'alloy', // Example speaker name }) ``` OpenAI Voice Provider の詳細については、[OpenAI Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/openai)を参照してください。 **Azure**: ```typescript // Azure Voice Configuration const voice = new AzureVoice({ speechModel: { name: 'en-US-JennyNeural', // Example model name apiKey: process.env.AZURE_SPEECH_KEY, region: process.env.AZURE_SPEECH_REGION, language: 'en-US', // Language code style: 'cheerful', // Voice style pitch: '+0Hz', // Pitch adjustment rate: '1.0', // Speech rate }, listeningModel: { name: 'en-US', // Example model name apiKey: process.env.AZURE_SPEECH_KEY, region: process.env.AZURE_SPEECH_REGION, format: 'simple', // Output format }, }) ``` Azure Voice Provider の詳細については、[Azure Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/azure)を参照してください。 **ElevenLabs**: ```typescript // ElevenLabs Voice Configuration const voice = new ElevenLabsVoice({ speechModel: { voiceId: 'your-voice-id', // Example voice ID model: 'eleven_multilingual_v2', // Example model name apiKey: process.env.ELEVENLABS_API_KEY, language: 'en', // Language code emotion: 'neutral', // Emotion setting }, // ElevenLabs may not have a separate listening model }) ``` ElevenLabs Voice Provider の詳細については、[ElevenLabs Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/elevenlabs)を参照してください。 **PlayAI**: ```typescript // PlayAI Voice Configuration const voice = new PlayAIVoice({ speechModel: { name: 'playai-voice', // Example model name speaker: 'emma', // Example speaker name apiKey: process.env.PLAYAI_API_KEY, language: 'en-US', // Language code speed: 1.0, // Speech speed }, // PlayAI may not have a separate listening model }) ``` PlayAI Voice Provider の詳細については、[PlayAI Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/playai)を参照してください。 **Google**: ```typescript // Google Voice Configuration const voice = new GoogleVoice({ speechModel: { name: 'en-US-Studio-O', // Example model name apiKey: process.env.GOOGLE_API_KEY, languageCode: 'en-US', // Language code gender: 'FEMALE', // Voice gender speakingRate: 1.0, // Speaking rate }, listeningModel: { name: 'en-US', // Example model name sampleRateHertz: 16000, // Sample rate }, }) ``` Google Voice Provider の詳細については、[Google Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/google)を参照してください。 **Cloudflare**: ```typescript // Cloudflare Voice Configuration const voice = new CloudflareVoice({ speechModel: { name: 'cloudflare-voice', // Example model name accountId: process.env.CLOUDFLARE_ACCOUNT_ID, apiToken: process.env.CLOUDFLARE_API_TOKEN, language: 'en-US', // Language code format: 'mp3', // Audio format }, // Cloudflare may not have a separate listening model }) ``` Cloudflare Voice Provider の詳細については、[Cloudflare Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/cloudflare)を参照してください。 **Deepgram**: ```typescript // Deepgram Voice Configuration const voice = new DeepgramVoice({ speechModel: { name: 'nova-2', // Example model name speaker: 'aura-english-us', // Example speaker name apiKey: process.env.DEEPGRAM_API_KEY, language: 'en-US', // Language code tone: 'formal', // Tone setting }, listeningModel: { name: 'nova-2', // Example model name format: 'flac', // Audio format }, }) ``` Deepgram Voice Provider の詳細については、[Deepgram Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/deepgram)を参照してください。 **Inworld**: ```typescript // Inworld Voice Configuration const voice = new InworldVoice({ speechModel: { name: 'inworld-tts-2', apiKey: process.env.INWORLD_API_KEY, }, listeningModel: { name: 'groq/whisper-large-v3', apiKey: process.env.INWORLD_API_KEY, }, speaker: 'Dennis', audioEncoding: 'MP3', sampleRateHertz: 48000, language: 'en-US', }) // Per-call options: `deliveryMode` is honored only by `inworld-tts-2`. const audioStream = await voice.speak('Hello!', { deliveryMode: 'BALANCED', // 'STABLE' | 'BALANCED' | 'CREATIVE' language: 'en-US', // BCP-47 per-call override }) ``` Inworld Voice Provider の詳細については、[Inworld Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/inworld)を参照してください。 **Speechify**: ```typescript // Speechify Voice Configuration const voice = new SpeechifyVoice({ speechModel: { name: 'speechify-voice', // Example model name speaker: 'matthew', // Example speaker name apiKey: process.env.SPEECHIFY_API_KEY, language: 'en-US', // Language code speed: 1.0, // Speech speed }, // Speechify may not have a separate listening model }) ``` Speechify Voice Provider の詳細については、[Speechify Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/speechify)を参照してください。 **Sarvam**: ```typescript // Sarvam Voice Configuration const voice = new SarvamVoice({ speechModel: { model: 'bulbul:v3', // TTS model (bulbul:v2 or bulbul:v3) apiKey: process.env.SARVAM_API_KEY, language: 'en-IN', // BCP-47 language code }, listeningModel: { model: 'saarika:v2.5', // STT model (saarika:v2.5 or saaras:v3) apiKey: process.env.SARVAM_API_KEY, }, speaker: 'shubh', // Default bulbul:v3 speaker }) ``` Sarvam Voice Provider の詳細については、[Sarvam Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/sarvam)を参照してください。 **Murf**: ```typescript // Murf Voice Configuration const voice = new MurfVoice({ speechModel: { name: 'murf-voice', // Example model name apiKey: process.env.MURF_API_KEY, language: 'en-US', // Language code emotion: 'happy', // Emotion setting }, // Murf may not have a separate listening model }) ``` Murf Voice Provider の詳細については、[Murf Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/murf)を参照してください。 **OpenAI Realtime**: ```typescript // OpenAI Realtime Voice Configuration const voice = new OpenAIRealtimeVoice({ speechModel: { name: 'gpt-3.5-turbo', // Example model name apiKey: process.env.OPENAI_API_KEY, language: 'en-US', // Language code }, listeningModel: { name: 'whisper-1', // Example model name apiKey: process.env.OPENAI_API_KEY, format: 'ogg', // Audio format }, speaker: 'alloy', // Example speaker name }) ``` OpenAI Realtime Voice Provider の詳細については、[OpenAI Realtime Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/openai-realtime)を参照してください。 **xAI Realtime**: ```typescript // xAI Realtime Voice Configuration const voice = new XAIRealtimeVoice({ apiKey: process.env.XAI_API_KEY, model: 'grok-voice-think-fast-1.0', speaker: 'eve', instructions: 'You are a concise voice assistant.', turnDetection: { type: 'server_vad', threshold: 0.85, silence_duration_ms: 1000, prefix_padding_ms: 333, }, audio: { input: { format: { type: 'audio/pcm', rate: 24000 } }, output: { format: { type: 'audio/pcm', rate: 24000 } }, }, serverTools: [ { type: 'web_search' }, { type: 'mcp', server_url: 'https://mcp.example.com/mcp', server_label: 'business-tools', }, ], }) ``` xAI Realtime Voice Provider の詳細については、[xAI Realtime Voice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/xai-realtime)を参照してください。 **Google Gemini Live**: ```typescript // Google Gemini Live Voice Configuration const voice = new GeminiLiveVoice({ speechModel: { name: 'gemini-2.0-flash-exp', // Example model name apiKey: process.env.GOOGLE_API_KEY, }, speaker: 'Puck', // Example speaker name // Google Gemini Live is a realtime bidirectional API without separate speech and listening models }) ``` Google Gemini Live Voice Provider の詳細については、[Google Gemini Live リファレンス](https://mastra.zisheng.pro/ja/reference/voice/google-gemini-live)を参照してください。 **AWS Nova Sonic**: ```typescript // AWS Nova Sonic Voice Configuration const voice = new NovaSonicVoice({ region: 'us-east-1', speaker: 'matthew', sessionConfig: { inferenceConfiguration: { temperature: 0.7, maxTokens: 1024, }, turnDetectionConfiguration: { endpointingSensitivity: 'MEDIUM', }, }, // AWS Nova Sonic is a realtime bidirectional API without separate speech and listening models }) ``` AWS Nova Sonic Voice Provider の詳細については、[AWS Nova Sonic リファレンス](https://mastra.zisheng.pro/ja/reference/voice/aws-nova-sonic)を参照してください。 **Inworld Realtime**: ```typescript // Inworld Realtime Voice Configuration const voice = new InworldRealtimeVoice({ apiKey: process.env.INWORLD_API_KEY, model: 'inworld/models/gemma-4-26b-a4b-it', speaker: 'Sarah', // Typed Inworld realtime knobs (semantic VAD, playback speed, MCP tool routing, ...) session: { audio: { output: { speed: 1.1 }, input: { turn_detection: { type: 'semantic_vad', eagerness: 'high' } }, }, }, }) ``` Inworld Realtime Voice Provider の詳細については、[Inworld Realtime リファレンス](https://mastra.zisheng.pro/ja/reference/voice/inworld-realtime)を参照してください。 **AI SDK**: ```typescript // AI SDK Voice Configuration import { CompositeVoice } from '@mastra/core/voice' import { openai } from '@ai-sdk/openai' import { elevenlabs } from '@ai-sdk/elevenlabs' // Use AI SDK models directly - no need to install separate packages const voice = new CompositeVoice({ input: openai.transcription('whisper-1'), // AI SDK transcription output: elevenlabs.speech('eleven_turbo_v2'), // AI SDK speech }) // Works seamlessly with your agent const voiceAgent = new Agent({ id: 'aisdk-voice-agent', name: 'AI SDK Voice Agent', instructions: 'You are a helpful assistant with voice capabilities.', model: 'openai/gpt-5.6-sol', voice, }) ``` ### 複数の Voice Provider を使用する この例では、Mastra で 2 つの異なる Voice Provider を作成して使用する方法を示します。Speech-to-Text(STT)には OpenAI、Text-to-Speech(TTS)には PlayAI を使用します。 まず、必要な設定を指定して Voice Provider のインスタンスを作成します。 ```typescript import { OpenAIVoice } from '@mastra/voice-openai' import { PlayAIVoice } from '@mastra/voice-playai' import { CompositeVoice } from '@mastra/core/voice' import { playAudio, getMicrophoneStream } from '@mastra/node-audio' // Initialize OpenAI voice for STT const input = new OpenAIVoice({ listeningModel: { name: 'whisper-1', apiKey: process.env.OPENAI_API_KEY, }, }) // Initialize PlayAI voice for TTS const output = new PlayAIVoice({ speechModel: { name: 'playai-voice', apiKey: process.env.PLAYAI_API_KEY, }, }) // Combine the providers using CompositeVoice const voice = new CompositeVoice({ input, output, }) // Implement voice interactions using the combined voice provider const audioStream = getMicrophoneStream() // Assume this function gets audio input const transcript = await voice.listen(audioStream) // Log the transcribed text console.log('Transcribed text:', transcript) // Convert text to speech const responseAudio = await voice.speak(`You said: ${transcript}`, { speaker: 'default', // Optional: specify a speaker, responseFormat: 'wav', // Optional: specify a response format }) // Play the audio response playAudio(responseAudio) ``` ### AI SDK Model Provider を使用する `CompositeVoice` では AI SDK モデルを直接使用することもできます。 ```typescript import { CompositeVoice } from '@mastra/core/voice' import { openai } from '@ai-sdk/openai' import { elevenlabs } from '@ai-sdk/elevenlabs' import { playAudio, getMicrophoneStream } from '@mastra/node-audio' // Use AI SDK models directly - no provider setup needed const voice = new CompositeVoice({ input: openai.transcription('whisper-1'), // AI SDK transcription output: elevenlabs.speech('eleven_turbo_v2'), // AI SDK speech }) // Works the same way as Mastra providers const audioStream = getMicrophoneStream() const transcript = await voice.listen(audioStream) console.log('Transcribed text:', transcript) // Convert text to speech const responseAudio = await voice.speak(`You said: ${transcript}`, { speaker: 'Rachel', // ElevenLabs voice }) playAudio(responseAudio) ``` AI SDK モデルと Mastra Provider を組み合わせることもできます。 ```typescript import { CompositeVoice } from '@mastra/core/voice' import { PlayAIVoice } from '@mastra/voice-playai' import { groq } from '@ai-sdk/groq' const voice = new CompositeVoice({ input: groq.transcription('whisper-large-v3'), // AI SDK for STT output: new PlayAIVoice(), // Mastra provider for TTS }) ``` CompositeVoice の詳細については、[CompositeVoice リファレンス](https://mastra.zisheng.pro/ja/reference/voice/composite-voice)を参照してください。 ## その他のリソース - [CompositeVoice](https://mastra.zisheng.pro/ja/reference/voice/composite-voice) - [MastraVoice](https://mastra.zisheng.pro/ja/reference/voice/mastra-voice) - [OpenAI Voice](https://mastra.zisheng.pro/ja/reference/voice/openai) - [OpenAI Realtime Voice](https://mastra.zisheng.pro/ja/reference/voice/openai-realtime) - [xAI Realtime Voice](https://mastra.zisheng.pro/ja/reference/voice/xai-realtime) - [Azure Voice](https://mastra.zisheng.pro/ja/reference/voice/azure) - [Google Voice](https://mastra.zisheng.pro/ja/reference/voice/google) - [Google Gemini Live Voice](https://mastra.zisheng.pro/ja/reference/voice/google-gemini-live) - [AWS Nova Sonic Voice](https://mastra.zisheng.pro/ja/reference/voice/aws-nova-sonic) - [Deepgram Voice](https://mastra.zisheng.pro/ja/reference/voice/deepgram) - [Inworld Voice](https://mastra.zisheng.pro/ja/reference/voice/inworld) - [LiveKit](https://mastra.zisheng.pro/ja/reference/voice/livekit) - [PlayAI Voice](https://mastra.zisheng.pro/ja/reference/voice/playai) - [Voice の例](https://github.com/mastra-ai/voice-examples)