Skip to main content

voice.updateConfig()

updateConfig() 方法允许你在运行时更新语音提供商的配置。这对于在不创建新实例的情况下更改语音设置、API 密钥或其他特定于提供商的选项非常有用。

🌐 The updateConfig() method allows you to update the configuration of a voice provider at runtime. This is useful for changing voice settings, API keys, or other provider-specific options without creating a new instance.

使用示例
Direct link to 使用示例

🌐 Usage Example

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!");

参数
Direct link to 参数

🌐 Parameters


options:

Record<string, unknown>
Configuration options to update. The specific properties depend on the voice provider.

返回值
Direct link to 返回值

🌐 Return Value

此方法不返回值。

🌐 This method does not return a value.

配置选项
Direct link to 配置选项

🌐 Configuration Options

不同的语音提供商支持不同的配置选项:

🌐 Different voice providers support different configuration options:

OpenAI 实时
Direct link to OpenAI 实时

🌐 OpenAI Realtime


voice?:

string
Voice ID to use for speech synthesis (e.g., 'alloy', 'echo', 'nova')

turn_detection?:

{ type: string, threshold?: number, silence_duration_ms?: number }
Configuration for detecting when a user has finished speaking

注意
Direct link to 注意

🌐 Notes

  • 如果提供程序不支持此方法,默认实现会记录一个警告
  • 配置更新通常应用于后续操作,而不是正在进行的操作
  • 并非所有在构造函数中可以设置的属性都可以在运行时更新
  • 具体行为取决于语音提供商的实现
  • 对于实时语音服务提供商,某些配置更改可能需要重新连接到服务