> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # Inworld Mastra の Inworld Voice 実装は、Inworld AI API を使用したストリーミング Text-to-Speech(TTS)およびバッチ Speech-to-Text(STT)機能を提供します。複数の TTS・STT モデル、設定可能な音声エンコーディング、プログレッシブ音声ストリーミングをサポートします。 リアルタイムの全二重音声間通信向けに、同じパッケージから [`InworldRealtimeVoice`](https://mastra.zisheng.pro/ja/reference/voice/inworld-realtime) もエクスポートされています。 ## 使用例 ```typescript import { InworldVoice } from '@mastra/voice-inworld' // Initialize with default configuration (uses INWORLD_API_KEY environment variable) const voice = new InworldVoice() // Initialize with custom configuration const voice = new InworldVoice({ speechModel: { name: 'inworld-tts-2', apiKey: 'your-api-key', }, listeningModel: { name: 'groq/whisper-large-v3', apiKey: 'your-api-key', }, speaker: 'Dennis', }) // Text-to-Speech (streaming) const audioStream = await voice.speak('Hello, world!') // Speech-to-Text const transcript = await voice.listen(audioStream) ``` ## コンストラクターパラメーター **speechModel** (`InworldVoiceConfig`): Text-to-Speech 機能の設定。 (Default: `{ name: 'inworld-tts-2' }`) **speechModel.name** (`'inworld-tts-2' | 'inworld-tts-1.5-max' | 'inworld-tts-1.5-mini'`): 使用する Inworld TTS モデル。 **speechModel.apiKey** (`string`): Inworld API キー。未指定の場合は INWORLD\_API\_KEY 環境変数を使用します。 **listeningModel** (`InworldListeningConfig`): Speech-to-Text 機能の設定。 (Default: `{ name: 'groq/whisper-large-v3' }`) **listeningModel.name** (`'groq/whisper-large-v3'`): 使用する Inworld STT モデル。 **listeningModel.apiKey** (`string`): Inworld API キー。未指定の場合は INWORLD\_API\_KEY 環境変数を使用します。 **speaker** (`string`): Text-to-Speech に使用するデフォルトの Voice ID。 (Default: `'Dennis'`) **audioEncoding** (`'LINEAR16' | 'MP3' | 'OGG_OPUS' | 'ALAW' | 'MULAW' | 'FLAC' | 'PCM' | 'WAV'`): TTS 出力のデフォルト音声エンコーディング。 (Default: `'MP3'`) **sampleRateHertz** (`number`): TTS 出力のデフォルトサンプルレート。 (Default: `48000`) **language** (`string`): STT のデフォルト BCP-47 言語コード。 (Default: `'en-US'`) ## メソッド ### `speak(input, options?)` Inworld のストリーミング TTS エンドポイントを使用してテキストを音声に変換します。到着した音声チャンクを順次送出する読み取り可能なストリームを返します。 ```typescript const audioStream = await voice.speak('Hello, world!', { speaker: 'Olivia', audioEncoding: 'WAV', sampleRateHertz: 24000, speakingRate: 1.2, temperature: 0.8, }) ``` **input** (`string | NodeJS.ReadableStream`): 音声に変換するテキスト。ストリームを指定した場合は、先にテキストへ変換されます。 **options** (`InworldSpeakOptions`): 音声合成の追加オプション。 **options.speaker** (`string`): このリクエストでデフォルトの Speaker を上書きします。 **options.audioEncoding** (`AudioEncoding`): デフォルトの音声エンコーディングを上書きします。 **options.sampleRateHertz** (`number`): デフォルトのサンプルレートを上書きします。 **options.speakingRate** (`number`): 発話速度を調整します。 **options.temperature** (`number`): Voice の変動性を制御します。inworld-tts-1.5-\* モデルでは有効ですが、inworld-tts-2 では無視されます。 **options.deliveryMode** (`'STABLE' | 'BALANCED' | 'CREATIVE'`): 表現スタイルを調整する制御。inworld-tts-2 だけで有効です。 **options.language** (`string`): このリクエストの BCP-47 言語コード。省略すると自動検出されます。 **戻り値:** `Promise` ### `listen(input, options?)` Inworld のバッチ STT エンドポイントを使用して音声をテキストに変換します。 ```typescript const transcript = await voice.listen(audioStream, { audioEncoding: 'MP3', sampleRateHertz: 44100, language: 'ja-JP', }) ``` **input** (`NodeJS.ReadableStream`): 文字起こしする音声ストリーム。 **options** (`InworldListenOptions`): 文字起こしの追加オプション。 **options.audioEncoding** (`'LINEAR16' | 'MP3' | 'OGG_OPUS' | 'FLAC' | 'AUTO_DETECT'`): 入力ストリームの音声エンコーディング。 **options.sampleRateHertz** (`number`): 入力音声のサンプルレート。 **options.language** (`string`): 文字起こしの BCP-47 言語コード。 **options.numberOfChannels** (`number`): 入力の音声チャンネル数。 **戻り値:** `Promise` ### `getSpeakers()` Inworld API から使用可能な Voice の一覧を返します。 ```typescript const speakers = await voice.getSpeakers() // [{ voiceId: 'Dennis', name: 'Dennis', language: 'en', description: '...', tags: ['friendly'], source: 'SYSTEM' }, ...] ``` **戻り値:** `Promise>` ## 注意事項 - TTS エンドポイントはプログレッシブ NDJSON ストリーミングを使用するため、完全な応答を受信する前に音声の再生を開始できます。 - API キーは `speechModel` または `listeningModel` の設定、あるいは `INWORLD_API_KEY` 環境変数で指定できます。TTS と STT のキーは個別に解決されます。`speechModel.apiKey` と `listeningModel.apiKey` に異なる値を渡すと、各サービスで独自の認証情報を使用できます。一方だけを指定した場合は、環境変数を参照する前のフォールバックとして両方のサービスで再利用されます。 - `inworld-tts-2` はデフォルトのフラッグシップモデルです。このモデルの表現スタイルを調整するには、`deliveryMode`(`STABLE` | `BALANCED` | `CREATIVE`)を使用します。`temperature` オプションは `inworld-tts-2` では無視されます。 - `inworld-tts-1.5-mini` モデルは、`inworld-tts-1.5-max` と比べて Voice 品質が低下する代わりに、より低いレイテンシーを実現します。