diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml index 724e0b7a..f2a18c84 100644 --- a/main/xiaozhi-server/config.yaml +++ b/main/xiaozhi-server/config.yaml @@ -520,3 +520,16 @@ module_test: - "你好,请介绍一下你自己" - "What's the weather like today?" - "请用100字概括量子计算的基本原理和应用前景" + +# 唤醒词,用于识别唤醒词还是讲话内容 +wakeup_words: + - "你好小智" + - "你好小志" + - "小爱同学" + - "你好小鑫" + - "你好小新" + - "小美同学" + - "小龙小龙" + - "喵喵同学" + - "小滨小滨" + - "小冰小冰" \ No newline at end of file diff --git a/main/xiaozhi-server/core/handle/textHandle.py b/main/xiaozhi-server/core/handle/textHandle.py index f1356068..3f60592a 100644 --- a/main/xiaozhi-server/core/handle/textHandle.py +++ b/main/xiaozhi-server/core/handle/textHandle.py @@ -2,6 +2,7 @@ from config.logger import setup_logging import json from core.handle.abortHandle import handleAbortMessage from core.handle.helloHandle import handleHelloMessage +from core.utils.util import remove_punctuation_and_length from core.handle.receiveAudioHandle import startToChat, handleAudioMessage from core.handle.sendAudioHandle import send_stt_message, send_tts_message from core.handle.iotHandle import handleIotDescriptors, handleIotStatus @@ -39,13 +40,21 @@ async def handleTextMessage(conn, message): conn.client_have_voice = False conn.asr_audio.clear() if "text" in msg_json: - if conn.config.get("enable_greeting", True): - # 启用开场白 通过llm回复唤醒词 - await startToChat(conn, msg_json["text"]) - else: - # 不启用 直接转为聆听状态 - await send_stt_message(conn, msg_json["text"]) + text = msg_json["text"] + _, text = remove_punctuation_and_length(text) + + # 识别是否是唤醒词 + is_wakeup_words = 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_tts_message(conn, "stop", None) + else: + # 否则需要LLM对文字内容进行答复 + await startToChat(conn, text) elif msg_json["type"] == "iot": if "descriptors" in msg_json: await handleIotDescriptors(conn, msg_json["descriptors"])