Skip to content

Commit f8e9f97

Browse files
wehosHongzhi Wenclaude
authored
fix(voice): 修复带工具调用的语音轮「有声无字」 (#1646)
* fix(voice): 修复带工具调用的语音轮「有声无字」 部分语音 provider(lanlan.app Gemini 代理)只发 response.audio_transcript.delta、 不发 response.audio_transcript.done,输出转录全靠 _print_input_transcript=True 的 streaming 分支实时送出。但工具调用(如 recall_memory)那一轮的 response.done 会把 _print_input_transcript 置 False,紧随其后的真回复转录便走 buffer 分支累积进 _output_transcript_buffer,无 transcript.done 来 flush,最终在 response.done 被直接 清空 → 前端有声无字。 在 response.done 清空 buffer 前补一次 flush:仅当本轮真出过声(audio_delta_count>0) 且 buffer 仍有残留时补发。streaming 分支每次都会清空 buffer,正常轮此处为 no-op, 不会重复发送。flush 在 on_response_done(turn_end) 之前触发,时序正确。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(voice): 兜底 flush 输出转录时加一条 debug 日志 「有声无字」是反复出现的问题,留一条 debug 日志方便下次诊断时区分是 response.done 兜底生效、还是 streaming / transcript.done 路径生效。 采纳 CodeRabbit 评审建议。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Hongzhi Wen <cartabio.coder1@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent baa6088 commit f8e9f97

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

main_logic/omni_realtime_client.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,6 +2639,33 @@ async def _run_tool(_name=name, _args=raw_args, _cid=call_id):
26392639
else:
26402640
self._last_response_transcript = ""
26412641
print(f"OmniRealtimeClient: response.done - 没有转录文本 | audio_deltas={self._audio_delta_count}")
2642+
# [有声无字兜底] 部分 provider(如 lanlan.app Gemini 语音代理)只发
2643+
# response.audio_transcript.delta、从不发 response.audio_transcript.done,
2644+
# 输出转录全靠下面 streaming 分支(_print_input_transcript=True)实时送出。
2645+
# 但带工具调用的一轮里,工具调用那一轮的 response.done 会把
2646+
# _print_input_transcript 置 False(见下方),紧随其后的真回复转录便走
2647+
# buffer 分支累积进 _output_transcript_buffer,没有 transcript.done 来 flush,
2648+
# 就在这里被直接清空 → 前端有声无字。这里在清空前补一次 flush:只要本轮真
2649+
# 出过声(audio_delta_count>0)且 buffer 仍有残留就补发。streaming 分支每次都
2650+
# 会清空 buffer,故正常轮此处为 no-op,不会重复发送。
2651+
if (
2652+
self._output_transcript_buffer
2653+
and self.on_output_transcript
2654+
and self._audio_delta_count > 0
2655+
):
2656+
# 「有声无字」是反复出现的问题(见上方 ISSUE4b),留一条 debug
2657+
# 日志方便下次诊断时确认是这条兜底生效、还是 streaming/transcript.done
2658+
# 路径生效。audio_delta_count 此处尚未清零,记录的是本轮真实值。
2659+
logger.debug(
2660+
"response.done 兜底 flush 输出转录: buffer_len=%d audio_deltas=%d is_first=%s",
2661+
len(self._output_transcript_buffer),
2662+
self._audio_delta_count,
2663+
self._is_first_transcript_chunk,
2664+
)
2665+
await self.on_output_transcript(
2666+
self._output_transcript_buffer, self._is_first_transcript_chunk
2667+
)
2668+
self._is_first_transcript_chunk = False
26422669
self._audio_delta_count = 0
26432670
# 确保 buffer 被清空
26442671
self._output_transcript_buffer = ""

0 commit comments

Comments
 (0)