实时语音Realtime voice · 单元Unit 10
实时语音:低延迟、可打断的交互Realtime voice: low-latency, interruptible interaction
实时链路由采集、传输、模型、播放四段组成。学完本单元,你能理解 VAD、轮次提交、打断取消和资源释放,并定位延迟与回声问题。The realtime path spans capture, transport, model and playback. After this unit you understand VAD, turn commits, barge-in cancellation and resource release, and can diagnose latency and echo issues.
学习目标Learning goals
- 说出实时语音链路的四个延迟段Name the four latency segments of realtime voice
- 使用 connect、push_audio、commit_turn 与 cancel_responseUse connect, push_audio, commit_turn and cancel_response
- 设计打断与资源回收策略Design barge-in and resource-reclamation strategies
概念闪卡Concept cards
点击卡片翻面查看解释。Click a card to flip it and reveal the explanation.
关键 APIKey APIs
点击进入对应的 Python 或 Java 参考页。Open the exact Python or Java reference for each type.
问题巩固Check yourself
完成 10 道题;答错会自动进入错题本。Answer all ten questions. Wrong answers are added to your wrong-answer book automatically.
01Python 实时模型的公共基类是?What is the common base class for Python realtime models?
解析Why RealtimeModelBase 提供连接、推音频、推文本、提交轮次和取消响应等能力。RealtimeModelBase provides connect, audio/text push, turn commit and response cancellation.
02Python 中负责实时会话的智能体类是?Which Python agent class handles realtime sessions?
解析Why RealtimeAgent 提供 connect、send、reply_stream、interrupt 和 close。RealtimeAgent provides connect, send, reply_stream, interrupt and close.
03建立实时模型连接的方法是?How do you establish a realtime model connection?
解析Why connect 建立长连接;连接是长生命周期资源,关闭时必须显式释放。connect establishes a long-lived connection; it must be released explicitly on shutdown.
04向实时模型推送音频的方法是?How do you push audio into a realtime model?
解析Why push_audio 推送音频帧;发送侧传输由 TransportBase 的 send_audio 负责。push_audio pushes audio frames; the transport side uses TransportBase.send_audio.
05取消当前未完成响应的 API 是?Which API cancels an unfinished response?
解析Why 用户打断时应 cancel_response 并清空待播音频,避免继续播放旧回复。On barge-in, call cancel_response and clear pending audio to stop the old reply.
06结束一轮用户语音输入并请求响应的 API 是?Which API ends a user turn and requests a response?
解析Why commit_turn 提交当前轮次;request_response 请求模型生成响应。commit_turn commits the current turn; request_response asks the model to generate.
07语音活动检测的抽象基类是?What is the voice activity detection abstraction?
解析Why VADBase 提供 push 与 reset,用于判定语音开始和结束。VADBase provides push and reset for detecting speech start and end.
08音频传输的抽象基类是?What is the audio transport abstraction?
解析Why TransportBase 负责 start、send_audio、clear_audio 和 playout。TransportBase handles start, send_audio, clear_audio and playout.
09实时语音延迟应该拆成哪四段度量?Which four segments should realtime latency be measured in?
解析Why 分段度量才能判断瓶颈在端侧、网络、模型还是播放缓冲。Segmenting reveals whether the bottleneck is the device, network, model or playback buffer.
10实时连接使用完毕后必须做什么?What must you do after a realtime connection is no longer needed?
解析Why 长连接与音频设备不释放会导致句柄泄漏和麦克风占用。Unreleased long-lived connections and audio devices leak handles and keep the microphone busy.