diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml index a3c54c17d..bb341dcca 100644 --- a/main/xiaozhi-server/config.yaml +++ b/main/xiaozhi-server/config.yaml @@ -67,6 +67,8 @@ enable_wakeup_words_response_cache: true enable_greeting: true # 说完话是否开启提示音 enable_stop_tts_notify: false +# Disable listen during chat to prevent barge-in +disable_listen_during_chat: false # 说完话是否开启提示音,音效地址 stop_tts_notify_voice: "config/assets/tts_notify.mp3" # 是否启用WebSocket心跳保活机制 @@ -290,6 +292,7 @@ ASR: FunASR: type: fun_local model_dir: models/SenseVoiceSmall + language: zh # auto/zh/en etc output_dir: tmp/ FunASRServer: # 独立部署FunASR,使用FunASR的API服务,只需要五句话 diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index da13949d5..2b80b00e9 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -927,6 +927,7 @@ class ConnectionHandler: ) except Exception as e: self.logger.bind(tag=TAG).error(f"LLM 处理出错 {query}: {e}") + self.llm_finish_task = True return None # 处理流式响应(满足:非 action、未产 content、0.5s 无信息增加 => thinking) diff --git a/main/xiaozhi-server/core/handle/receiveAudioHandle.py b/main/xiaozhi-server/core/handle/receiveAudioHandle.py index ec1d3bc71..594bc7f6f 100644 --- a/main/xiaozhi-server/core/handle/receiveAudioHandle.py +++ b/main/xiaozhi-server/core/handle/receiveAudioHandle.py @@ -21,6 +21,14 @@ async def handleAudioMessage(conn, audio): if not hasattr(conn, "vad_resume_task") or conn.vad_resume_task.done(): conn.vad_resume_task = asyncio.create_task(resume_vad_detection(conn)) return + # Disable listen during chat to prevent barge-in + if conn.config.get("disable_listen_during_chat", False): + if (not conn.llm_finish_task or conn.client_is_speaking) and conn.client_listen_mode != "manual": + await no_voice_close_connect(conn, have_voice) + if have_voice and hasattr(conn, "asr_audio"): + conn.asr_audio.clear() + return + # manual 模式下不打断正在播放的内容 if have_voice: if conn.client_is_speaking and conn.client_listen_mode != "manual": diff --git a/main/xiaozhi-server/core/providers/asr/fun_local.py b/main/xiaozhi-server/core/providers/asr/fun_local.py index 29579ecbc..f7f02c5ae 100644 --- a/main/xiaozhi-server/core/providers/asr/fun_local.py +++ b/main/xiaozhi-server/core/providers/asr/fun_local.py @@ -50,6 +50,7 @@ class ASRProvider(ASRProviderBase): self.interface_type = InterfaceType.LOCAL self.model_dir = config.get("model_dir") self.output_dir = config.get("output_dir") # 修正配置键名 + self.language = (config.get("language") or "auto").lower() self.delete_audio_file = delete_audio_file # 确保输出目录存在 @@ -98,11 +99,16 @@ class ASRProvider(ASRProviderBase): self.model.generate, input=combined_pcm_data, cache={}, - language="auto", + language=self.language, use_itn=True, batch_size_s=60, ) text = lang_tag_filter(result[0]["text"]) + if self.language != "auto": + if isinstance(text, dict): + text["language"] = self.language + else: + text = {"content": text, "language": self.language} logger.bind(tag=TAG).debug( f"语音识别耗时: {time.time() - start_time:.3f}s | 结果: {text['content']}" )