mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 09:33:55 +08:00
update:优化对唤醒词的识别
This commit is contained in:
@@ -520,3 +520,16 @@ module_test:
|
|||||||
- "你好,请介绍一下你自己"
|
- "你好,请介绍一下你自己"
|
||||||
- "What's the weather like today?"
|
- "What's the weather like today?"
|
||||||
- "请用100字概括量子计算的基本原理和应用前景"
|
- "请用100字概括量子计算的基本原理和应用前景"
|
||||||
|
|
||||||
|
# 唤醒词,用于识别唤醒词还是讲话内容
|
||||||
|
wakeup_words:
|
||||||
|
- "你好小智"
|
||||||
|
- "你好小志"
|
||||||
|
- "小爱同学"
|
||||||
|
- "你好小鑫"
|
||||||
|
- "你好小新"
|
||||||
|
- "小美同学"
|
||||||
|
- "小龙小龙"
|
||||||
|
- "喵喵同学"
|
||||||
|
- "小滨小滨"
|
||||||
|
- "小冰小冰"
|
||||||
@@ -2,6 +2,7 @@ from config.logger import setup_logging
|
|||||||
import json
|
import json
|
||||||
from core.handle.abortHandle import handleAbortMessage
|
from core.handle.abortHandle import handleAbortMessage
|
||||||
from core.handle.helloHandle import handleHelloMessage
|
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.receiveAudioHandle import startToChat, handleAudioMessage
|
||||||
from core.handle.sendAudioHandle import send_stt_message, send_tts_message
|
from core.handle.sendAudioHandle import send_stt_message, send_tts_message
|
||||||
from core.handle.iotHandle import handleIotDescriptors, handleIotStatus
|
from core.handle.iotHandle import handleIotDescriptors, handleIotStatus
|
||||||
@@ -39,13 +40,21 @@ async def handleTextMessage(conn, message):
|
|||||||
conn.client_have_voice = False
|
conn.client_have_voice = False
|
||||||
conn.asr_audio.clear()
|
conn.asr_audio.clear()
|
||||||
if "text" in msg_json:
|
if "text" in msg_json:
|
||||||
if conn.config.get("enable_greeting", True):
|
text = msg_json["text"]
|
||||||
# 启用开场白 通过llm回复唤醒词
|
_, text = remove_punctuation_and_length(text)
|
||||||
await startToChat(conn, msg_json["text"])
|
|
||||||
else:
|
# 识别是否是唤醒词
|
||||||
# 不启用 直接转为聆听状态
|
is_wakeup_words = text in conn.config.get("wakeup_words")
|
||||||
await send_stt_message(conn, msg_json["text"])
|
# 是否开启唤醒词回复
|
||||||
|
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)
|
await send_tts_message(conn, "stop", None)
|
||||||
|
else:
|
||||||
|
# 否则需要LLM对文字内容进行答复
|
||||||
|
await startToChat(conn, text)
|
||||||
elif msg_json["type"] == "iot":
|
elif msg_json["type"] == "iot":
|
||||||
if "descriptors" in msg_json:
|
if "descriptors" in msg_json:
|
||||||
await handleIotDescriptors(conn, msg_json["descriptors"])
|
await handleIotDescriptors(conn, msg_json["descriptors"])
|
||||||
|
|||||||
Reference in New Issue
Block a user