From 2625133f407125b77bfa3d2c940154655b43e519 Mon Sep 17 00:00:00 2001 From: Sakura-RanChen <1908198662@qq.com> Date: Wed, 9 Jul 2025 17:04:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=93=E6=96=AD=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=9C=AA=E9=87=8D=E7=BD=AE=20=E7=9B=91=E5=90=AC=E6=9C=AA?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=97=B6=E6=9C=8D=E5=8A=A1=E7=AB=AF=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E8=BF=98=E5=9C=A8=E5=8F=91=E9=80=81=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=20=E6=AD=A4=E6=97=B6=E5=A4=8D=E7=94=A8=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E4=BC=9A=E6=8E=A5=E6=94=B6=E4=B8=8A=E4=B8=AA=E8=AF=AD=E9=9F=B3?= =?UTF-8?q?=E7=9A=84=E6=AE=8B=E4=BD=99=20=E9=9C=80=E8=A6=81=E4=B8=A4?= =?UTF-8?q?=E8=80=85=E4=B8=80=E5=90=8C=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/providers/tts/base.py | 2 ++ .../core/providers/tts/huoshan_double_stream.py | 15 +++------------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/main/xiaozhi-server/core/providers/tts/base.py b/main/xiaozhi-server/core/providers/tts/base.py index c89b3247..9127ec12 100644 --- a/main/xiaozhi-server/core/providers/tts/base.py +++ b/main/xiaozhi-server/core/providers/tts/base.py @@ -195,6 +195,8 @@ class TTSProviderBase(ABC): while not self.conn.stop_event.is_set(): try: message = self.tts_text_queue.get(timeout=1) + if message.sentence_type == SentenceType.FIRST: + self.conn.client_abort = False if self.conn.client_abort: logger.bind(tag=TAG).info("收到打断信息,终止TTS文本处理线程") continue diff --git a/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py b/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py index e6e4d2fa..0eb7c72d 100644 --- a/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py +++ b/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py @@ -310,18 +310,9 @@ class TTSProvider(TTSProviderBase): and isinstance(self._monitor_task, Task) and not self._monitor_task.done() ): - logger.bind(tag=TAG).info("取消上一个监听任务...") - self._monitor_task.cancel() - try: - # 等待任务取消完成 - await asyncio.wait_for(self._monitor_task, timeout=3) - except asyncio.CancelledError: - logger.bind(tag=TAG).info("监听任务已成功取消") - except asyncio.TimeoutError: - logger.bind(tag=TAG).warning("取消监听任务超时,可能仍在运行") - except Exception as e: - logger.bind(tag=TAG).warning(f"取消监听任务异常: {e}") - self._monitor_task = None + logger.bind(tag=TAG).info("检测到未完成的上个会话,关闭监听任务和连接...") + await self.close() + # 建立新连接 await self._ensure_connection()