voice.updateConfig()
updateConfig() 方法允许你在 runtime 更新 Voice Provider 的配置。需要更改 Voice 设置、API key 或特定于 Provider 的其他选项而又不想创建新实例时,此方法非常有用。
使用示例使用示例的直接链接
import { OpenAIRealtimeVoice } from '@mastra/voice-openai-realtime'
// Initialize a real-time voice provider
const voice = new OpenAIRealtimeVoice({
realtimeConfig: {
model: 'gpt-5.1-realtime',
apiKey: process.env.OPENAI_API_KEY,
},
speaker: 'alloy',
})
// Connect to the real-time service
await voice.connect()
// Later, update the configuration
voice.updateConfig({
voice: 'nova', // Change the default voice
turn_detection: {
type: 'server_vad',
threshold: 0.5,
silence_duration_ms: 1000,
},
})
// The next speak() call will use the new configuration
await voice.speak('Hello with my new voice!')
参数参数的直接链接
options:
Record<string, unknown>
要更新的配置选项。具体属性取决于 Voice Provider。
返回值返回值的直接链接
此方法不返回值。
配置选项配置选项的直接链接
不同 Voice Provider 支持不同的配置选项:
OpenAI RealtimeOpenAI Realtime的直接链接
voice?:
string
用于语音合成的 Voice ID(例如 'alloy'、'echo'、'nova')
turn_detection?:
{ type: string, threshold?: number, silence_duration_ms?: number }
用于检测用户何时结束发言的配置
注意事项注意事项的直接链接
- 如果 Provider 不支持此方法,默认实现会记录警告
- 配置更新通常会应用于后续操作,而不是正在进行的操作
- 并非构造函数中可设置的所有属性都能在 runtime 更新
- 具体行为取决于 Voice Provider 的实现
- 对于实时 Voice Provider,某些配置更改可能需要重新连接服务