> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # voice.answer() `answer()` 方法用于触发实时 Voice Provider 中的 AI 生成响应。在语音对语音对话中,当收到用户输入后需要显式通知 AI 进行响应时,此方法尤其有用。 ## 使用示例 ```typescript import { OpenAIRealtimeVoice } from '@mastra/voice-openai-realtime' import { getMicrophoneStream } from '@mastra/node-audio' import Speaker from '@mastra/node-speaker' const speaker = new Speaker({ sampleRate: 24100, // Audio sample rate in Hz - standard for high-quality audio on MacBook Pro channels: 1, // Mono audio output (as opposed to stereo which would be 2) bitDepth: 16, // Bit depth for audio quality - CD quality standard (16-bit resolution) }) // Initialize a real-time voice provider const voice = new OpenAIRealtimeVoice({ realtimeConfig: { model: 'gpt-5.1', apiKey: process.env.OPENAI_API_KEY, }, speaker: 'alloy', // Default voice }) // Connect to the real-time service await voice.connect() // Register event listener for responses voice.on('speaker', stream => { // Handle audio response stream.pipe(speaker) }) // Send user audio input const microphoneStream = getMicrophoneStream() await voice.send(microphoneStream) // Trigger the AI to respond await voice.answer() ``` ## 参数 **options** (`Record`): 用于响应的 Provider 特定选项 ## 返回值 返回 `Promise`,在响应触发后完成。 ## 注意事项 - 只有支持语音对语音功能的实时 Voice Provider 才实现此方法 - 如果在不支持此功能的 Voice Provider 上调用此方法,它会记录警告并立即完成 - 响应音频通常会通过 'speaking' 事件发出,而不是直接返回 - 对于支持此功能的 Provider,可以使用此方法发送指定响应,而不是让 AI 生成响应 - 此方法通常与 `send()` 结合使用,以形成对话流程