> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # OpenAI Mastra の OpenAIVoice クラスは、OpenAI モデルを使用した Text-to-Speech および Speech-to-Text 機能を提供します。 ## 使用例 ```typescript import { OpenAIVoice } from '@mastra/voice-openai' // Initialize with default configuration using environment variables const voice = new OpenAIVoice() // Or initialize with specific configuration const voiceWithConfig = new OpenAIVoice({ speechModel: { name: 'tts-1-hd', apiKey: 'your-openai-api-key', }, listeningModel: { name: 'whisper-1', apiKey: 'your-openai-api-key', }, speaker: 'alloy', // Default voice }) // Convert text to speech const audioStream = await voice.speak('Hello, how can I help you?', { speaker: 'nova', // Override default voice speed: 1.2, // Adjust speech speed }) // Convert speech to text const text = await voice.listen(audioStream, { filetype: 'mp3', }) ``` ## 設定 ### コンストラクターオプション **speechModel** (`OpenAIConfig`): Text-to-Speech 合成の設定。 (Default: `{ name: 'tts-1' }`) **speechModel.name** (`'tts-1' | 'tts-1-hd' | 'whisper-1'`): モデル名。より高品質な音声には 'tts-1-hd' を使用します。 **speechModel.apiKey** (`string`): OpenAI API キー。未指定の場合は OPENAI\_API\_KEY 環境変数を使用します。 **listeningModel** (`OpenAIConfig`): Speech-to-Text 認識の設定。 (Default: `{ name: 'whisper-1' }`) **listeningModel.name** (`'tts-1' | 'tts-1-hd' | 'whisper-1'`): モデル名。より高品質な音声には 'tts-1-hd' を使用します。 **listeningModel.apiKey** (`string`): OpenAI API キー。未指定の場合は OPENAI\_API\_KEY 環境変数を使用します。 **speaker** (`OpenAIVoiceId`): 音声合成に使用するデフォルトの Voice ID。 (Default: `'alloy'`) ## メソッド ### `speak()` OpenAI の Text-to-Speech モデルを使用してテキストを音声に変換します。 **input** (`string | NodeJS.ReadableStream`): 音声に変換するテキストまたはテキストストリーム。 **options** (`Options`): 設定オプション。 **options.speaker** (`OpenAIVoiceId`): 音声合成に使用する Voice ID。 **options.speed** (`number`): 発話速度の倍率。 戻り値:`Promise` ### `listen()` OpenAI の Whisper モデルを使用して音声を文字起こしします。 **audioStream** (`NodeJS.ReadableStream`): 文字起こしする音声ストリーム。 **options** (`Options`): 設定オプション。 **options.filetype** (`string`): 入力ストリームの音声形式。 戻り値:`Promise` ### `getSpeakers()` 使用可能な Voice オプションの配列を返します。各要素には次の値が含まれます。 **voiceId** (`string`): Voice の一意な識別子 ## 注意事項 - API キーは、コンストラクターオプションまたは `OPENAI_API_KEY` 環境変数で指定できます - `tts-1-hd` モデルはより高品質な音声を提供しますが、処理に時間がかかる場合があります - 音声認識は mp3、wav、webm など複数の音声形式をサポートします