From 05331f001a134ec8e8f50121288e0a669d22bfcc Mon Sep 17 00:00:00 2001 From: Sakura-RanChen <1908198662@qq.com> Date: Tue, 6 May 2025 15:15:27 +0800 Subject: [PATCH] =?UTF-8?q?update:=20tts=E8=B6=85=E6=97=B6=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E6=96=87=E6=9C=AC=E7=B4=A2=E5=BC=95=E6=B7=B7?= =?UTF-8?q?=E4=B9=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/connection.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index f08a61ff..1fe63912 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -565,7 +565,7 @@ class ConnectionHandler: future = self.executor.submit( self.speak_and_play, segment_text, text_index ) - self.tts_queue.put(future) + self.tts_queue.put((future, text_index)) processed_chars += len(segment_text_raw) # 更新已处理字符位置 # 处理最后剩余的文本 @@ -695,7 +695,7 @@ class ConnectionHandler: future = self.executor.submit( self.speak_and_play, segment_text, text_index ) - self.tts_queue.put(future) + self.tts_queue.put((future, text_index)) # 更新已处理字符位置 processed_chars += len(segment_text_raw) @@ -859,7 +859,10 @@ class ConnectionHandler: text = None try: try: - future = self.tts_queue.get(timeout=1) + item = self.tts_queue.get(timeout=1) + if item is None: + continue + future, text_index = item # 解包获取 Future 和 text_index except queue.Empty: if self.stop_event.is_set(): break @@ -867,11 +870,11 @@ class ConnectionHandler: if future is None: continue text = None - opus_datas, text_index, tts_file = [], 0, None + opus_datas, tts_file = [], None try: self.logger.bind(tag=TAG).debug("正在处理TTS任务...") tts_timeout = int(self.config.get("tts_timeout", 10)) - tts_file, text, text_index = future.result(timeout=tts_timeout) + tts_file, text, _ = future.result(timeout=tts_timeout) if text is None or len(text) <= 0: self.logger.bind(tag=TAG).error( f"TTS出错:{text_index}: tts text is empty"