メインコンテンツへ移動

Inworld

Mastra の Inworld Voice 実装は、Inworld AI API を使用したストリーミング Text-to-Speech(TTS)およびバッチ Speech-to-Text(STT)機能を提供します。複数の TTS・STT モデル、設定可能な音声エンコーディング、プログレッシブ音声ストリーミングをサポートします。

リアルタイムの全二重音声間通信向けに、同じパッケージから InworldRealtimeVoice もエクスポートされています。

使用例
使用例への直接リンク

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
= { name: 'inworld-tts-2' }
Text-to-Speech 機能の設定。
InworldVoiceConfig

name?:

'inworld-tts-2' | 'inworld-tts-1.5-max' | 'inworld-tts-1.5-mini'
使用する Inworld TTS モデル。

apiKey?:

string
Inworld API キー。未指定の場合は INWORLD_API_KEY 環境変数を使用します。

listeningModel?:

InworldListeningConfig
= { name: 'groq/whisper-large-v3' }
Speech-to-Text 機能の設定。
InworldListeningConfig

name?:

'groq/whisper-large-v3'
使用する Inworld STT モデル。

apiKey?:

string
Inworld API キー。未指定の場合は INWORLD_API_KEY 環境変数を使用します。

speaker?:

string
= 'Dennis'
Text-to-Speech に使用するデフォルトの Voice ID。

audioEncoding?:

'LINEAR16' | 'MP3' | 'OGG_OPUS' | 'ALAW' | 'MULAW' | 'FLAC' | 'PCM' | 'WAV'
= 'MP3'
TTS 出力のデフォルト音声エンコーディング。

sampleRateHertz?:

number
= 48000
TTS 出力のデフォルトサンプルレート。

language?:

string
= 'en-US'
STT のデフォルト BCP-47 言語コード。

メソッド
メソッドへの直接リンク

speak(input, options?)
speakinput-optionsへの直接リンク

Inworld のストリーミング TTS エンドポイントを使用してテキストを音声に変換します。到着した音声チャンクを順次送出する読み取り可能なストリームを返します。

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
音声合成の追加オプション。
InworldSpeakOptions

speaker?:

string
このリクエストでデフォルトの Speaker を上書きします。

audioEncoding?:

AudioEncoding
デフォルトの音声エンコーディングを上書きします。

sampleRateHertz?:

number
デフォルトのサンプルレートを上書きします。

speakingRate?:

number
発話速度を調整します。

temperature?:

number
Voice の変動性を制御します。inworld-tts-1.5-* モデルでは有効ですが、inworld-tts-2 では無視されます。

deliveryMode?:

'STABLE' | 'BALANCED' | 'CREATIVE'
表現スタイルを調整する制御。inworld-tts-2 だけで有効です。

language?:

string
このリクエストの BCP-47 言語コード。省略すると自動検出されます。

戻り値: Promise<NodeJS.ReadableStream>

listen(input, options?)
listeninput-optionsへの直接リンク

Inworld のバッチ STT エンドポイントを使用して音声をテキストに変換します。

const transcript = await voice.listen(audioStream, {
audioEncoding: 'MP3',
sampleRateHertz: 44100,
language: 'ja-JP',
})

input:

NodeJS.ReadableStream
文字起こしする音声ストリーム。

options?:

InworldListenOptions
文字起こしの追加オプション。
InworldListenOptions

audioEncoding?:

'LINEAR16' | 'MP3' | 'OGG_OPUS' | 'FLAC' | 'AUTO_DETECT'
入力ストリームの音声エンコーディング。

sampleRateHertz?:

number
入力音声のサンプルレート。

language?:

string
文字起こしの BCP-47 言語コード。

numberOfChannels?:

number
入力の音声チャンネル数。

戻り値: Promise<string>

getSpeakers()
getspeakersへの直接リンク

Inworld API から使用可能な Voice の一覧を返します。

const speakers = await voice.getSpeakers()
// [{ voiceId: 'Dennis', name: 'Dennis', language: 'en', description: '...', tags: ['friendly'], source: 'SYSTEM' }, ...]

戻り値: Promise<Array<{ voiceId: string; name: string; language: string; description: string; tags: string[]; source: string }>>

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

  • TTS エンドポイントはプログレッシブ NDJSON ストリーミングを使用するため、完全な応答を受信する前に音声の再生を開始できます。
  • API キーは speechModel または listeningModel の設定、あるいは INWORLD_API_KEY 環境変数で指定できます。TTS と STT のキーは個別に解決されます。speechModel.apiKeylisteningModel.apiKey に異なる値を渡すと、各サービスで独自の認証情報を使用できます。一方だけを指定した場合は、環境変数を参照する前のフォールバックとして両方のサービスで再利用されます。
  • inworld-tts-2 はデフォルトのフラッグシップモデルです。このモデルの表現スタイルを調整するには、deliveryModeSTABLE | BALANCED | CREATIVE)を使用します。temperature オプションは inworld-tts-2 では無視されます。
  • inworld-tts-1.5-mini モデルは、inworld-tts-1.5-max と比べて Voice 品質が低下する代わりに、より低いレイテンシーを実現します。