From d5fc4d48b44902f7d26025ab5e695d3f1717d42d Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Sun, 8 Jun 2025 02:33:07 +0800 Subject: [PATCH] =?UTF-8?q?update:=E4=BC=98=E5=8C=96=E6=B5=81=E5=A4=B1?= =?UTF-8?q?=E5=89=8D=E5=B8=A7=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/handle/receiveAudioHandle.py | 3 +-- .../providers/tts/huoshan_double_stream.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/main/xiaozhi-server/core/handle/receiveAudioHandle.py b/main/xiaozhi-server/core/handle/receiveAudioHandle.py index 3b98a638..fd58f49d 100644 --- a/main/xiaozhi-server/core/handle/receiveAudioHandle.py +++ b/main/xiaozhi-server/core/handle/receiveAudioHandle.py @@ -13,15 +13,14 @@ TAG = __name__ async def handleAudioMessage(conn, audio): # 当前片段是否有人说话 have_voice = conn.vad.is_vad(conn, audio) - # 如果设备刚刚被唤醒,短暂忽略VAD检测 if have_voice and hasattr(conn, "just_woken_up") and conn.just_woken_up: have_voice = False # 设置一个短暂延迟后恢复VAD检测 conn.asr_audio.clear() if not hasattr(conn, "vad_resume_task") or conn.vad_resume_task.done(): - print("clear asr_audio") conn.vad_resume_task = asyncio.create_task(resume_vad_detection(conn)) + return if have_voice: if conn.client_is_speaking: 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 33a1c8ec..8245b754 100644 --- a/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py +++ b/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py @@ -381,6 +381,7 @@ class TTSProvider(TTSProviderBase): """监听TTS响应""" opus_datas_cache = [] is_first_sentence = True + first_sentence_segment_count = 0 # 添加计数器 try: while not self.conn.stop_event.is_set(): try: @@ -402,6 +403,7 @@ class TTSProvider(TTSProviderBase): (SentenceType.FIRST, [], self.tts_text) ) opus_datas_cache = [] + first_sentence_segment_count = 0 # 重置计数器 elif ( res.optional.event == EVENT_TTSResponse and res.header.message_type == AUDIO_ONLY_RESPONSE @@ -412,19 +414,22 @@ class TTSProvider(TTSProviderBase): f"推送数据到队列里面帧数~~{len(opus_datas)}" ) if is_first_sentence: - # 第一句话直接发送 - self.tts_audio_queue.put( - (SentenceType.MIDDLE, opus_datas, self.tts_text) - ) + first_sentence_segment_count += 1 + if first_sentence_segment_count <= 6: + self.tts_audio_queue.put( + (SentenceType.MIDDLE, opus_datas, None) + ) + else: + opus_datas_cache = opus_datas_cache + opus_datas else: # 后续句子缓存 opus_datas_cache = opus_datas_cache + opus_datas elif res.optional.event == EVENT_TTSSentenceEnd: logger.bind(tag=TAG).info(f"句子语音生成成功:{self.tts_text}") - if not is_first_sentence: - # 只有非第一句话才发送缓存的数据 + if not is_first_sentence or first_sentence_segment_count > 10: + # 发送缓存的数据 self.tts_audio_queue.put( - (SentenceType.MIDDLE, opus_datas_cache, self.tts_text) + (SentenceType.MIDDLE, opus_datas_cache, None) ) # 第一句话结束后,将标志设置为False is_first_sentence = False