From a647f3c105230ee35a91fadf2cf321d5e1638fe4 Mon Sep 17 00:00:00 2001 From: CGD <3030332422@qq.com> Date: Mon, 19 May 2025 15:18:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=E8=A7=A3=E5=86=B3=E7=AC=A6=E5=8F=B7?= =?UTF-8?q?=E8=AF=AF=E8=AF=86=E5=88=AB=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/handle/helloHandle.py | 4 ++-- main/xiaozhi-server/core/handle/intentHandler.py | 5 +++-- .../xiaozhi-server/core/handle/receiveAudioHandle.py | 10 +++++----- main/xiaozhi-server/core/handle/textHandle.py | 12 ++++++------ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/main/xiaozhi-server/core/handle/helloHandle.py b/main/xiaozhi-server/core/handle/helloHandle.py index f902a64f..e29ef450 100644 --- a/main/xiaozhi-server/core/handle/helloHandle.py +++ b/main/xiaozhi-server/core/handle/helloHandle.py @@ -40,8 +40,8 @@ async def checkWakeupWords(conn, text): if not enable_wakeup_words_response_cache: return False """检查是否是唤醒词""" - _, text = remove_punctuation_and_length(text) - if text in conn.config.get("wakeup_words"): + _, filtered_text = remove_punctuation_and_length(text) + if filtered_text in conn.config.get("wakeup_words"): await send_stt_message(conn, text) conn.tts_first_text_index = 0 conn.tts_last_text_index = 0 diff --git a/main/xiaozhi-server/core/handle/intentHandler.py b/main/xiaozhi-server/core/handle/intentHandler.py index 1cae8bab..495da96f 100644 --- a/main/xiaozhi-server/core/handle/intentHandler.py +++ b/main/xiaozhi-server/core/handle/intentHandler.py @@ -13,10 +13,11 @@ TAG = __name__ async def handle_user_intent(conn, text): # 检查是否有明确的退出命令 - if await check_direct_exit(conn, text): + filtered_text = remove_punctuation_and_length(text)[1] + if await check_direct_exit(conn, filtered_text): return True # 检查是否是唤醒词 - if await checkWakeupWords(conn, text): + if await checkWakeupWords(conn, filtered_text): return True if conn.intent_type == "function_call": diff --git a/main/xiaozhi-server/core/handle/receiveAudioHandle.py b/main/xiaozhi-server/core/handle/receiveAudioHandle.py index ee6a1d5c..9c693751 100644 --- a/main/xiaozhi-server/core/handle/receiveAudioHandle.py +++ b/main/xiaozhi-server/core/handle/receiveAudioHandle.py @@ -39,14 +39,14 @@ async def handleAudioMessage(conn, audio): if len(conn.asr_audio) < 15: conn.asr_server_receive = True else: - text, _ = await conn.asr.speech_to_text(conn.asr_audio, conn.session_id) - conn.logger.bind(tag=TAG).info(f"识别文本: {text}") - text_len, _ = remove_punctuation_and_length(text) + raw_text, _ = await conn.asr.speech_to_text(conn.asr_audio, conn.session_id) # 确保ASR模块返回原始文本 + conn.logger.bind(tag=TAG).info(f"识别文本: {raw_text}") + text_len, _ = remove_punctuation_and_length(raw_text) if text_len > 0: # 使用自定义模块进行上报 - enqueue_asr_report(conn, text, copy.deepcopy(conn.asr_audio)) + enqueue_asr_report(conn, raw_text, copy.deepcopy(conn.asr_audio)) - await startToChat(conn, text) + await startToChat(conn, raw_text) else: conn.asr_server_receive = True conn.asr_audio.clear() diff --git a/main/xiaozhi-server/core/handle/textHandle.py b/main/xiaozhi-server/core/handle/textHandle.py index 79874f1c..c7827409 100644 --- a/main/xiaozhi-server/core/handle/textHandle.py +++ b/main/xiaozhi-server/core/handle/textHandle.py @@ -42,17 +42,17 @@ async def handleTextMessage(conn, message): conn.client_have_voice = False conn.asr_audio.clear() if "text" in msg_json: - text = msg_json["text"] - _, text = remove_punctuation_and_length(text) + original_text = msg_json["text"] # 保留原始文本 + filtered_len, filtered_text = remove_punctuation_and_length(original_text) # 识别是否是唤醒词 - is_wakeup_words = text in conn.config.get("wakeup_words") + is_wakeup_words = filtered_text in conn.config.get("wakeup_words") # 是否开启唤醒词回复 enable_greeting = conn.config.get("enable_greeting", True) if is_wakeup_words and not enable_greeting: # 如果是唤醒词,且关闭了唤醒词回复,就不用回答 - await send_stt_message(conn, text) + await send_stt_message(conn, original_text) await send_tts_message(conn, "stop", None) elif is_wakeup_words: # 上报纯文字数据(复用ASR上报功能,但不提供音频数据) @@ -60,9 +60,9 @@ async def handleTextMessage(conn, message): await startToChat(conn, "嘿,你好呀") else: # 上报纯文字数据(复用ASR上报功能,但不提供音频数据) - enqueue_asr_report(conn, text, []) + enqueue_asr_report(conn, original_text, []) # 否则需要LLM对文字内容进行答复 - await startToChat(conn, text) + await startToChat(conn, original_text) elif msg_json["type"] == "iot": if "descriptors" in msg_json: asyncio.create_task(handleIotDescriptors(conn, msg_json["descriptors"])) From ebc16207f436d96d77e8d53e951135bd82f40e9d Mon Sep 17 00:00:00 2001 From: CGD <3030332422@qq.com> Date: Tue, 20 May 2025 10:54:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?update:intent=5Fllm=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=B8=8E=E9=80=80=E5=87=BA=E7=9B=B8=E5=85=B3=E7=9A=84=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/providers/intent/intent_llm/intent_llm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main/xiaozhi-server/core/providers/intent/intent_llm/intent_llm.py b/main/xiaozhi-server/core/providers/intent/intent_llm/intent_llm.py index 2a3e023f..ee657420 100644 --- a/main/xiaozhi-server/core/providers/intent/intent_llm/intent_llm.py +++ b/main/xiaozhi-server/core/providers/intent/intent_llm/intent_llm.py @@ -53,6 +53,8 @@ class IntentProvider(IntentProviderBase): prompt = ( "你是一个意图识别助手。请分析用户的最后一句话,判断用户意图并调用相应的函数。\n\n" + "- 如果用户使用疑问词(如'怎么'、'为什么'、'如何')询问退出相关的问题(例如'怎么退出了?'),注意这不是让你退出,请返回 {'function_call': {'name': 'continue_chat'}\n" + "- 仅当用户明确使用'退出系统'、'结束对话'、'我不想和你说话了'等指令时,才触发 handle_exit_intent\n\n" f"{functions_desc}\n" "处理步骤:\n" "1. 分析用户输入,确定用户意图\n"