From c60850ef3d8542f7f1d9d5c343730b5f284ba7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=84=E5=87=A4=E7=A7=91=E6=8A=80?= Date: Fri, 14 Feb 2025 10:29:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=B9=E9=94=99=E5=88=A4?= =?UTF-8?q?=E6=96=AD=20=E8=A7=A3=E5=86=B3ollama=E6=8F=90=E4=BE=9B=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E5=9B=9E=E7=AD=94=E5=88=86=E5=89=B2=E5=90=8E=E6=9C=80?= =?UTF-8?q?=E5=90=8E=E4=B8=80=E5=8F=A5=E4=B8=BA=E7=A9=BA=EF=BC=8Cspeak?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E5=81=9C=E6=AD=A2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/connection.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/connection.py b/core/connection.py index 3f59762f..6972af76 100644 --- a/core/connection.py +++ b/core/connection.py @@ -138,9 +138,10 @@ class ConnectionHandler: # 处理剩余的响应 if start < len(response_message): segment_text = "".join(response_message[start:]) - self.recode_first_last_text(segment_text) - future = self.executor.submit(self.speak_and_play, segment_text) - self.tts_queue.put(future) + if len(segment_text) > 0: + self.recode_first_last_text(segment_text) + future = self.executor.submit(self.speak_and_play, segment_text) + self.tts_queue.put(future) self.llm_finish_task = True # 更新对话 @@ -159,6 +160,11 @@ class ConnectionHandler: try: self.logger.debug("正在处理TTS任务...") tts_file, text = future.result(timeout=10) + if text is None or len(text) <= 0: + continue + if tts_file is None: + self.logger.error(f"TTS文件生成失败: {text}") + continue self.logger.debug(f"TTS文件生成完毕,文件路径: {tts_file}") if os.path.exists(tts_file): opus_datas, duration = self.tts.wav_to_opus_data(tts_file) @@ -191,11 +197,11 @@ class ConnectionHandler: def speak_and_play(self, text): if text is None or len(text) <= 0: self.logger.info(f"无需tts转换,query为空,{text}") - return None + return None, text tts_file = self.tts.to_tts(text) if tts_file is None: self.logger.error(f"tts转换失败,{text}") - return None + return None, text self.logger.debug(f"TTS 文件生成完毕: {tts_file}") return tts_file, text