mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-26 17:13:54 +08:00
fix:解决符号误识别问题
This commit is contained in:
@@ -40,8 +40,8 @@ async def checkWakeupWords(conn, text):
|
|||||||
if not enable_wakeup_words_response_cache:
|
if not enable_wakeup_words_response_cache:
|
||||||
return False
|
return False
|
||||||
"""检查是否是唤醒词"""
|
"""检查是否是唤醒词"""
|
||||||
_, text = remove_punctuation_and_length(text)
|
_, filtered_text = remove_punctuation_and_length(text)
|
||||||
if text in conn.config.get("wakeup_words"):
|
if filtered_text in conn.config.get("wakeup_words"):
|
||||||
await send_stt_message(conn, text)
|
await send_stt_message(conn, text)
|
||||||
conn.tts_first_text_index = 0
|
conn.tts_first_text_index = 0
|
||||||
conn.tts_last_text_index = 0
|
conn.tts_last_text_index = 0
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ TAG = __name__
|
|||||||
|
|
||||||
async def handle_user_intent(conn, text):
|
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
|
return True
|
||||||
# 检查是否是唤醒词
|
# 检查是否是唤醒词
|
||||||
if await checkWakeupWords(conn, text):
|
if await checkWakeupWords(conn, filtered_text):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if conn.intent_type == "function_call":
|
if conn.intent_type == "function_call":
|
||||||
|
|||||||
@@ -39,14 +39,14 @@ async def handleAudioMessage(conn, audio):
|
|||||||
if len(conn.asr_audio) < 15:
|
if len(conn.asr_audio) < 15:
|
||||||
conn.asr_server_receive = True
|
conn.asr_server_receive = True
|
||||||
else:
|
else:
|
||||||
text, _ = await conn.asr.speech_to_text(conn.asr_audio, conn.session_id)
|
raw_text, _ = await conn.asr.speech_to_text(conn.asr_audio, conn.session_id) # 确保ASR模块返回原始文本
|
||||||
conn.logger.bind(tag=TAG).info(f"识别文本: {text}")
|
conn.logger.bind(tag=TAG).info(f"识别文本: {raw_text}")
|
||||||
text_len, _ = remove_punctuation_and_length(text)
|
text_len, _ = remove_punctuation_and_length(raw_text)
|
||||||
if text_len > 0:
|
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:
|
else:
|
||||||
conn.asr_server_receive = True
|
conn.asr_server_receive = True
|
||||||
conn.asr_audio.clear()
|
conn.asr_audio.clear()
|
||||||
|
|||||||
@@ -42,17 +42,17 @@ 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:
|
||||||
text = msg_json["text"]
|
original_text = msg_json["text"] # 保留原始文本
|
||||||
_, text = remove_punctuation_and_length(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)
|
enable_greeting = conn.config.get("enable_greeting", True)
|
||||||
|
|
||||||
if is_wakeup_words and not enable_greeting:
|
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)
|
await send_tts_message(conn, "stop", None)
|
||||||
elif is_wakeup_words:
|
elif is_wakeup_words:
|
||||||
# 上报纯文字数据(复用ASR上报功能,但不提供音频数据)
|
# 上报纯文字数据(复用ASR上报功能,但不提供音频数据)
|
||||||
@@ -60,9 +60,9 @@ async def handleTextMessage(conn, message):
|
|||||||
await startToChat(conn, "嘿,你好呀")
|
await startToChat(conn, "嘿,你好呀")
|
||||||
else:
|
else:
|
||||||
# 上报纯文字数据(复用ASR上报功能,但不提供音频数据)
|
# 上报纯文字数据(复用ASR上报功能,但不提供音频数据)
|
||||||
enqueue_asr_report(conn, text, [])
|
enqueue_asr_report(conn, original_text, [])
|
||||||
# 否则需要LLM对文字内容进行答复
|
# 否则需要LLM对文字内容进行答复
|
||||||
await startToChat(conn, text)
|
await startToChat(conn, original_text)
|
||||||
elif msg_json["type"] == "iot":
|
elif msg_json["type"] == "iot":
|
||||||
if "descriptors" in msg_json:
|
if "descriptors" in msg_json:
|
||||||
asyncio.create_task(handleIotDescriptors(conn, msg_json["descriptors"]))
|
asyncio.create_task(handleIotDescriptors(conn, msg_json["descriptors"]))
|
||||||
|
|||||||
Reference in New Issue
Block a user