From 635520aa8550382164d6d5880e8815324688b698 Mon Sep 17 00:00:00 2001 From: Ken Date: Tue, 25 Mar 2025 18:05:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?edge-tts=20=E6=B5=81=E5=BC=8F=E5=86=99?= =?UTF-8?q?=E5=85=A5=EF=BC=8C=E9=81=BF=E5=85=8D=E4=B8=80=E6=AC=A1=E6=80=A7?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=AE=8C=E6=95=B4=E8=AF=AD=E9=9F=B3=E5=88=B0?= =?UTF-8?q?=E5=86=85=E5=AD=98=EF=BC=8C=E6=97=A0=E9=9C=80=E7=AD=89=E5=BE=85?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E9=9F=B3=E9=A2=91=E7=94=9F=E6=88=90=E5=86=8D?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=EF=BC=8C=E9=9F=B3=E9=A2=91=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=9D=97=EF=BC=88chunk=EF=BC=89=E7=94=9F=E6=88=90=E5=90=8E?= =?UTF-8?q?=E7=AB=8B=E5=8D=B3=E5=86=99=E5=85=A5=E6=96=87=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E7=9B=B8=E6=AF=94=E7=AD=89=E5=BE=85=E5=AE=8C=E6=95=B4=E9=9F=B3?= =?UTF-8?q?=E9=A2=91=E7=94=9F=E6=88=90=E5=90=8E=E5=86=8D=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=EF=BC=8C=E8=83=BD=E6=9B=B4=E6=97=A9=E5=BE=97=E5=88=B0=E9=83=A8?= =?UTF-8?q?=E5=88=86=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"]) From ab93ee0406b4e63b2956543a6c60f40756051d92 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Wed, 26 Mar 2025 00:39:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?update:=E8=B0=83=E6=95=B4=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/connection.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index c9a52b12..4692a270 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -184,15 +184,15 @@ class ConnectionHandler: await handleAudioMessage(self, message) def _initialize_components(self): - """加载插件""" - self.func_handler = FunctionHandler(self) - """加载提示词""" self.prompt = self.config["prompt"] if self.private_config: self.prompt = self.private_config.private_config.get("prompt", self.prompt) self.dialogue.put(Message(role="system", content=self.prompt)) + """加载插件""" + self.func_handler = FunctionHandler(self) + """加载记忆""" device_id = self.headers.get("device-id", None) self.memory.init_memory(device_id, self.llm)