Skip to main content

语音事件

🌐 Voice Events

语音提供商在实时语音交互过程中会发出各种事件。可以使用 voice.on() 方法监听这些事件,它们对于构建交互式语音应用尤其重要。

🌐 Voice providers emit various events during real-time voice interactions. These events can be listened to using the voice.on() method and are particularly important for building interactive voice applications.

常见事件
Direct link to 常见事件

🌐 Common Events

这些事件通常在实时语音提供商中实现:

🌐 These events are commonly implemented across real-time voice providers:

error:

Error
Emitted when an error occurs during voice processing or when audio data format is unsupported

session.created:

object
Emitted when a new session is created with the OpenAI service

session.updated:

object
Emitted when the session configuration is updated

response.created:

object
Emitted when a new response is created by the AI assistant

response.done:

object
Emitted when the AI assistant has completed its response

speaker:

StreamWithId
Emitted with a new audio stream that can be piped to an audio output

writing:

object
Emitted when text is being transcribed (user) or generated (assistant)

speaking:

object
Emitted when audio data is available from the voice provider

speaking.done:

object
Emitted when the voice provider has finished speaking

tool-call-start:

object
Emitted when the AI assistant starts executing a tool

tool-call-result:

object
Emitted when a tool execution is complete with its result

注意
Direct link to 注意

🌐 Notes

  • 并非所有事件都被所有语音提供商支持
  • 具体的负载结构可能因提供商而异
  • 对于非实时提供商,大多数这些事件将不会被触发
  • 事件对于构建响应对话状态的交互式用户界面非常有用
  • 考虑在不再需要事件监听器时使用 voice.off() 方法来移除它们