From 032f6f1582e3743d875840f0368ed0bcf636460a Mon Sep 17 00:00:00 2001 From: Sakura-RanChen <1908198662@qq.com> Date: Tue, 27 Oct 2026 10:36:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=94=A4=E9=86=92?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E9=94=99=E8=AF=AF=E9=98=BB=E5=A1=9E=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=8E=A5=E6=94=B6=E5=BE=AA=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/handle/helloHandle.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/main/xiaozhi-server/core/handle/helloHandle.py b/main/xiaozhi-server/core/handle/helloHandle.py index 630c843bf..10c9d49f0 100644 --- a/main/xiaozhi-server/core/handle/helloHandle.py +++ b/main/xiaozhi-server/core/handle/helloHandle.py @@ -120,12 +120,12 @@ async def checkWakeupWords(conn: "ConnectionHandler", text): # 将唤醒词回复视为新会话,生成新的 sentence_id,确保流控器重置 conn.sentence_id = str(uuid.uuid4().hex) - conn.logger.bind(tag=TAG).info(f"播放唤醒词回复: {response.get('text')}") - await sendAudioMessage(conn, SentenceType.FIRST, opus_packets, response.get("text")) - await sendAudioMessage(conn, SentenceType.LAST, [], None) - # 补充对话 conn.dialogue.put(Message(role="assistant", content=response.get("text"))) + conn.logger.bind(tag=TAG).info(f"播放唤醒词回复: {response.get('text')}") + + await sendAudioMessage(conn, SentenceType.FIRST, opus_packets, response.get("text")) + asyncio.create_task(_finish_wakeup_reply(conn)) # 检查是否需要更新唤醒词回复 if time.time() - response.get("time", 0) > WAKEUP_CONFIG["refresh_time"]: @@ -134,6 +134,16 @@ async def checkWakeupWords(conn: "ConnectionHandler", text): return True +async def _finish_wakeup_reply(conn: "ConnectionHandler"): + """等音频队列清空后再发 stop(时序:全部音频帧→stop),期间不阻塞接收循环""" + try: + await sendAudioMessage(conn, SentenceType.LAST, [], None) + except asyncio.CancelledError: + raise + except Exception as e: + conn.logger.bind(tag=TAG).error(f"唤醒词回复收尾失败: {e}") + + async def wakeupWordsResponse(conn: "ConnectionHandler"): if not conn.tts: return