From 9a5aaea8ca1a735a65ba1269c8039eaeccf07d82 Mon Sep 17 00:00:00 2001 From: wnk Date: Sat, 26 Apr 2025 07:04:07 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=20tts=E6=9C=AA=E5=8F=8A=E6=97=B6?= =?UTF-8?q?=E5=93=8D=E5=BA=94=EF=BC=8C=E5=A4=9A=E6=AC=A1=E5=B0=9D=E8=AF=95?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BF=AE=E5=A4=8D=E3=80=82=EF=BC=88=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E7=A9=BA=E6=96=87=E4=BB=B6=EF=BC=8C=E8=BE=BE=E6=88=90?= =?UTF-8?q?While=E7=9A=84=E6=9D=A1=E4=BB=B6=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/providers/tts/base.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main/xiaozhi-server/core/providers/tts/base.py b/main/xiaozhi-server/core/providers/tts/base.py index b83f6f06..e668459c 100644 --- a/main/xiaozhi-server/core/providers/tts/base.py +++ b/main/xiaozhi-server/core/providers/tts/base.py @@ -29,16 +29,20 @@ class TTSProviderBase(ABC): try: asyncio.run(self.text_to_speak(text, tmp_file)) except Exception as e: - logger.bind(tag=TAG).error(f"语音生成失败: {text},错误: {e}") - if not os.path.exists(tmp_file): + logger.bind(tag=TAG).warning(f"语音生成失败{5 - max_repeat_time + 1}次: {text},错误: {e}") + # 未执行成功,删除文件 + if os.path.exists(tmp_file): + os.remove(tmp_file) max_repeat_time -= 1 - if max_repeat_time > 0: - logger.bind(tag=TAG).error(f"再试{max_repeat_time}次") if max_repeat_time > 0: logger.bind(tag=TAG).info( f"语音生成成功: {text}:{tmp_file},重试{5 - max_repeat_time}次" ) + else: + logger.bind(tag=TAG).error( + f"语音生成失败: {text},请检查网络或服务是否正常" + ) return tmp_file except Exception as e: