> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # Speech-to-Text(STT) Mastra の Speech-to-Text(STT)は、複数のサービス Provider で音声入力をテキストに変換するための標準化されたインターフェースを提供します。 STT により、音声対応アプリケーションは人の発話に応答できます。ハンズフリー操作に対応し、障害のあるユーザーのアクセシビリティを高め、より自然なインターフェースを提供します。 ## 設定 Mastra で STT を使用するには、Voice Provider の初期化時に `listeningModel` を指定します。これには次のようなパラメーターが含まれます。 - **`name`**: 使用する STT モデル。 - **`apiKey`**: 認証に使用する API キー。 - **Provider 固有のオプション**: Voice Provider ごとに必要またはサポートされる追加オプション。 **動作**: これらのパラメーターはすべて任意です。使用する Voice Provider に応じて、Provider が用意するデフォルト設定を使用できます。 ```typescript const voice = new OpenAIVoice({ listeningModel: { name: 'whisper-1', apiKey: process.env.OPENAI_API_KEY, }, }) // If using default settings the configuration can be simplified to: const voice = new OpenAIVoice() ``` ## 利用可能な Provider Mastra は複数の Speech-to-Text Provider をサポートしており、それぞれに異なる機能と長所があります。 - [**OpenAI**](https://mastra.zisheng.pro/ja/reference/voice/openai): Whisper モデルによる高精度な文字起こし - [**Azure**](https://mastra.zisheng.pro/ja/reference/voice/azure): エンタープライズレベルの信頼性を備えた Microsoft の音声認識 - [**ElevenLabs**](https://mastra.zisheng.pro/ja/reference/voice/elevenlabs): 複数言語に対応する高度な音声認識 - [**Google**](https://mastra.zisheng.pro/ja/reference/voice/google): 幅広い言語に対応する Google の音声認識 - [**Cloudflare**](https://mastra.zisheng.pro/ja/reference/voice/cloudflare): 低遅延アプリケーション向けにエッジ最適化された音声認識 - [**Deepgram**](https://mastra.zisheng.pro/ja/reference/voice/deepgram): さまざまなアクセントを高精度で認識する AI 音声認識 - [**Sarvam**](https://mastra.zisheng.pro/ja/reference/voice/sarvam): インド諸語とそのアクセントに特化 各 Provider は個別のパッケージとして実装されており、必要に応じてインストールできます。 ```bash pnpm add @mastra/voice-openai@latest # Example for OpenAI ``` ## listen メソッドを使用する STT の中心となる `listen()` メソッドは、音声をテキストに変換します。使用方法を次に示します。 ```typescript import { Agent } from '@mastra/core/agent' import { OpenAIVoice } from '@mastra/voice-openai' import { getMicrophoneStream } from '@mastra/node-audio' const voice = new OpenAIVoice() const agent = new Agent({ id: 'voice-agent', name: 'Voice Agent', instructions: 'You are a voice assistant that provides recommendations based on user input.', model: 'openai/gpt-5.6-sol', voice, }) const audioStream = getMicrophoneStream() // Assume this function gets audio input const transcript = await agent.voice.listen(audioStream, { filetype: 'm4a', // Optional: specify the audio file type }) console.log(`User said: ${transcript}`) const { text } = await agent.generate( `Based on what the user said, provide them a recommendation: ${transcript}`, ) console.log(`Recommendation: ${text}`) ``` ## 音声ファイルを文字起こしする `listen()` メソッドは、マイクまたはファイルからの音声データストリームを受け取ります。音声ファイルを文字起こしする場合は `createReadStream()` を使用します。 ```typescript import { createReadStream } from 'fs' import path from 'path' const audioFilePath = path.join(process.cwd(), 'agent.m4a') const audioStream = createReadStream(audioFilePath) const transcription = await agent.voice.listen(audioStream, { filetype: 'm4a', }) console.log(`Transcription: ${transcription}`) ``` Agent で利用できる Voice Provider の概要については、[Mastra の Voice](https://mastra.zisheng.pro/ja/guides/voice/overview)を参照してください。