mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 15:13:55 +08:00
fix: 打断状态未重置 监听未完成时服务端可能还在发送数据 此时复用链接会接收上个语音的残余 需要两者一同关闭
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user