From d7f0e88801b20677a93fc43594c47913bf4417cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=8E=E4=BE=A8?= Date: Wed, 28 May 2025 15:47:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=81=AB=E5=B1=B1=E5=8F=8C=E5=90=91=E6=B5=81?= =?UTF-8?q?=E5=BC=8Ftts=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/providers/tts/huoshan_double_stream.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py b/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py index 095437a9..1e76f538 100644 --- a/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py +++ b/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py @@ -236,6 +236,7 @@ class TTSProvider(TTSProviderBase): ) async def _start_monitor_tts_response(self): + opus_datas_cache = [] while not self.conn.stop_event.is_set(): try: msg = await self.ws.recv() # 确保 `recv()` 运行在同一个 event loop @@ -245,8 +246,9 @@ class TTSProvider(TTSProviderBase): if res.optional.event == EVENT_TTSSentenceStart: json_data = json.loads(res.payload.decode("utf-8")) self.tts_text = json_data.get("text", "") - logger.bind(tag=TAG).info(f"语音生成成功: {self.tts_text}") + logger.bind(tag=TAG).debug(f"句子语音生成开始: {self.tts_text}") self.tts_audio_queue.put((SentenceType.FIRST, [], self.tts_text)) + opus_datas_cache = [] elif ( res.optional.event == EVENT_TTSResponse and res.header.message_type == AUDIO_ONLY_RESPONSE @@ -256,9 +258,10 @@ class TTSProvider(TTSProviderBase): logger.bind(tag=TAG).debug( f"推送数据到队列里面帧数~~{len(opus_datas)}" ) - self.tts_audio_queue.put((SentenceType.MIDDLE, opus_datas, None)) + opus_datas_cache = opus_datas_cache + opus_datas elif res.optional.event == EVENT_TTSSentenceEnd: - logger.bind(tag=TAG).debug(f"句子结束~~{self.tts_text}") + logger.bind(tag=TAG).info(f"句子语音生成成功:{self.tts_text}") + self.tts_audio_queue.put((SentenceType.MIDDLE, opus_datas_cache, self.tts_text)) elif res.optional.event == EVENT_SessionFinished: logger.bind(tag=TAG).debug(f"会话结束~~") for tts_file, text in self.before_stop_play_files: