From 5b8a567f2636e0281b0407be8f1c154a28cf8067 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Wed, 4 Jun 2025 18:33:29 +0800 Subject: [PATCH] =?UTF-8?q?update:=E8=B1=86=E5=8C=85tts=E6=B5=81=E5=BC=8FA?= =?UTF-8?q?SR=E7=A9=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/handle/receiveAudioHandle.py | 4 ++-- .../xiaozhi-server/core/providers/asr/base.py | 2 +- .../core/providers/asr/doubao_stream.py | 23 +++++++++++-------- .../providers/tts/huoshan_double_stream.py | 7 +++--- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/main/xiaozhi-server/core/handle/receiveAudioHandle.py b/main/xiaozhi-server/core/handle/receiveAudioHandle.py index aee54cef..4c8c2c2e 100644 --- a/main/xiaozhi-server/core/handle/receiveAudioHandle.py +++ b/main/xiaozhi-server/core/handle/receiveAudioHandle.py @@ -30,8 +30,8 @@ async def handleAudioMessage(conn, audio): async def resume_vad_detection(conn): - # 等待1秒后恢复VAD检测 - await asyncio.sleep(1) + # 等待2秒后恢复VAD检测 + await asyncio.sleep(2) conn.just_woken_up = False diff --git a/main/xiaozhi-server/core/providers/asr/base.py b/main/xiaozhi-server/core/providers/asr/base.py index 5f2507c5..71098a20 100644 --- a/main/xiaozhi-server/core/providers/asr/base.py +++ b/main/xiaozhi-server/core/providers/asr/base.py @@ -82,9 +82,9 @@ class ASRProviderBase(ABC): ) # 确保ASR模块返回原始文本 conn.logger.bind(tag=TAG).info(f"识别文本: {raw_text}") text_len, _ = remove_punctuation_and_length(raw_text) + self.stop_ws_connection() if text_len > 0: # 使用自定义模块进行上报 - self.stop_ws_connection() await startToChat(conn, raw_text) enqueue_asr_report(conn, raw_text, asr_audio_task) diff --git a/main/xiaozhi-server/core/providers/asr/doubao_stream.py b/main/xiaozhi-server/core/providers/asr/doubao_stream.py index a81caf4e..491fd785 100644 --- a/main/xiaozhi-server/core/providers/asr/doubao_stream.py +++ b/main/xiaozhi-server/core/providers/asr/doubao_stream.py @@ -54,12 +54,8 @@ class ASRProvider(ASRProviderBase): await super().open_audio_channels(conn) async def receive_audio(self, conn, audio, audio_have_voice): - if not isinstance(audio, bytes): - return - conn.asr_audio.append(audio) - if audio_have_voice == False and conn.client_have_voice == False: - conn.asr_audio = conn.asr_audio[-10:] + conn.asr_audio = conn.asr_audio[-10:] # 如果本次有声音,且之前没有建立连接 if audio_have_voice and self.asr_ws is None and not self.is_processing: @@ -114,9 +110,6 @@ class ASRProvider(ASRProviderBase): # 发送缓存的音频数据 if conn.asr_audio and len(conn.asr_audio) > 0: - logger.bind(tag=TAG).info( - f"发送缓存音频数据: {len(conn.asr_audio)}" - ) for cached_audio in conn.asr_audio[-10:]: try: pcm_frame = self.decoder.decode(cached_audio, 960) @@ -166,6 +159,18 @@ class ASRProvider(ASRProviderBase): payload = result["payload_msg"] if "result" in payload: utterances = payload["result"].get("utterances", []) + # 检查duration和空文本的情况 + if ( + payload.get("audio_info", {}).get("duration", 0) > 2000 + and not utterances + and not payload["result"].get("text") + ): + logger.bind(tag=TAG).error(f"识别文本:空") + self.text = "" + conn.reset_vad_states() + await self.handle_voice_stop(conn, None) + break + for utterance in utterances: if utterance.get("definite", False): self.text = utterance["text"] @@ -235,7 +240,7 @@ class ASRProvider(ASRProviderBase): "sample_rate": self.rate, }, } - logger.bind(tag=TAG).info( + logger.bind(tag=TAG).debug( f"构造请求参数: {json.dumps(req, ensure_ascii=False)}" ) return req 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 4d15204e..b9dc399b 100644 --- a/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py +++ b/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py @@ -195,7 +195,7 @@ class TTSProvider(TTSProviderBase): try: logger.bind(tag=TAG).debug("等待TTS文本队列消息...") message = self.tts_text_queue.get(timeout=1) - logger.bind(tag=TAG).info( + logger.bind(tag=TAG).debug( f"收到TTS任务|{message.sentence_type.name} | {message.content_type.name} | 会话ID: {self.conn.sentence_id}" ) if self.conn.client_abort: @@ -221,7 +221,7 @@ class TTSProvider(TTSProviderBase): elif ContentType.TEXT == message.content_type: if message.content_detail: try: - logger.bind(tag=TAG).info( + logger.bind(tag=TAG).debug( f"开始发送TTS文本: {message.content_detail}" ) future = asyncio.run_coroutine_threadsafe( @@ -229,7 +229,7 @@ class TTSProvider(TTSProviderBase): loop=self.conn.loop, ) future.result() - logger.bind(tag=TAG).info("TTS文本发送成功") + logger.bind(tag=TAG).debug("TTS文本发送成功") except Exception as e: logger.bind(tag=TAG).error(f"发送TTS文本失败: {str(e)}") continue @@ -250,7 +250,6 @@ class TTSProvider(TTSProviderBase): loop=self.conn.loop, ) future.result() - logger.bind(tag=TAG).info("TTS会话结束成功") except Exception as e: logger.bind(tag=TAG).error(f"结束TTS会话失败: {str(e)}") continue