From 635520aa8550382164d6d5880e8815324688b698 Mon Sep 17 00:00:00 2001 From: Ken Date: Tue, 25 Mar 2025 18:05:25 +0800 Subject: [PATCH] =?UTF-8?q?edge-tts=20=E6=B5=81=E5=BC=8F=E5=86=99=E5=85=A5?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E4=B8=80=E6=AC=A1=E6=80=A7=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E5=AE=8C=E6=95=B4=E8=AF=AD=E9=9F=B3=E5=88=B0=E5=86=85?= =?UTF-8?q?=E5=AD=98=EF=BC=8C=E6=97=A0=E9=9C=80=E7=AD=89=E5=BE=85=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E9=9F=B3=E9=A2=91=E7=94=9F=E6=88=90=E5=86=8D=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=EF=BC=8C=E9=9F=B3=E9=A2=91=E6=95=B0=E6=8D=AE=E5=9D=97?= =?UTF-8?q?=EF=BC=88chunk=EF=BC=89=E7=94=9F=E6=88=90=E5=90=8E=E7=AB=8B?= =?UTF-8?q?=E5=8D=B3=E5=86=99=E5=85=A5=E6=96=87=E4=BB=B6=EF=BC=8C=E7=9B=B8?= =?UTF-8?q?=E6=AF=94=E7=AD=89=E5=BE=85=E5=AE=8C=E6=95=B4=E9=9F=B3=E9=A2=91?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=90=8E=E5=86=8D=E4=BF=9D=E5=AD=98=EF=BC=8C?= =?UTF-8?q?=E8=83=BD=E6=9B=B4=E6=97=A9=E5=BE=97=E5=88=B0=E9=83=A8=E5=88=86?= =?UTF-8?q?=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/providers/tts/edge.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main/xiaozhi-server/core/providers/tts/edge.py b/main/xiaozhi-server/core/providers/tts/edge.py index 3c02597d..289961cb 100644 --- a/main/xiaozhi-server/core/providers/tts/edge.py +++ b/main/xiaozhi-server/core/providers/tts/edge.py @@ -14,5 +14,14 @@ class TTSProvider(TTSProviderBase): return os.path.join(self.output_file, f"tts-{datetime.now().date()}@{uuid.uuid4().hex}{extension}") async def text_to_speak(self, text, output_file): - communicate = edge_tts.Communicate(text, voice=self.voice) # Use your preferred voice - await communicate.save(output_file) + communicate = edge_tts.Communicate(text, voice=self.voice) + # 确保目录存在并创建空文件 + os.makedirs(os.path.dirname(output_file), exist_ok=True) + with open(output_file, 'wb') as f: + pass + + # 流式写入音频数据 + with open(output_file, 'ab') as f: # 改为追加模式避免覆盖 + async for chunk in communicate.stream(): + if chunk["type"] == "audio": # 只处理音频数据块 + f.write(chunk["data"])