diff --git a/main/xiaozhi-server/core/handle/helloHandle.py b/main/xiaozhi-server/core/handle/helloHandle.py index 1edeefcd..95b16109 100644 --- a/main/xiaozhi-server/core/handle/helloHandle.py +++ b/main/xiaozhi-server/core/handle/helloHandle.py @@ -2,6 +2,7 @@ import time import json import random import asyncio +from core.utils.dialogue import Message from core.utils.util import audio_to_data from core.handle.sendAudioHandle import sendAudioMessage, send_stt_message from core.utils.util import remove_punctuation_and_length, opus_datas_to_wav_bytes @@ -79,6 +80,9 @@ async def checkWakeupWords(conn, text): await sendAudioMessage(conn, SentenceType.FIRST, opus_packets, response["text"]) await sendAudioMessage(conn, SentenceType.LAST, [], None) + # 补充对话 + conn.dialogue.put(Message(role="assistant", content=response["text"])) + # 检查是否需要更新唤醒词回复 if time.time() - response["time"] > WAKEUP_CONFIG["refresh_time"]: if not _wakeup_response_lock.locked(): diff --git a/main/xiaozhi-server/core/utils/textUtils.py b/main/xiaozhi-server/core/utils/textUtils.py index 7fadd3ff..603d964c 100644 --- a/main/xiaozhi-server/core/utils/textUtils.py +++ b/main/xiaozhi-server/core/utils/textUtils.py @@ -9,26 +9,38 @@ def get_string_no_punctuation_or_emoji(s): end = len(chars) - 1 while end >= start and is_punctuation_or_emoji(chars[end]): end -= 1 - return ''.join(chars[start:end + 1]) + return "".join(chars[start : end + 1]) + def is_punctuation_or_emoji(char): """检查字符是否为空格、指定标点或表情符号""" # 定义需要去除的中英文标点(包括全角/半角) punctuation_set = { - ',', ',', # 中文逗号 + 英文逗号 - '。', '.', # 中文句号 + 英文句号 - '!', '!', # 中文感叹号 + 英文感叹号 - '-', '-', # 英文连字符 + 中文全角横线 - '、' # 中文顿号 + ",", + ",", # 中文逗号 + 英文逗号 + "。", + ".", # 中文句号 + 英文句号 + "!", + "!", # 中文感叹号 + 英文感叹号 + "-", + "-", # 英文连字符 + 中文全角横线 + "、", # 中文顿号 + "[", + "]", # 方括号 + "【", + "】", # 中文方括号 } if char.isspace() or char in punctuation_set: return True # 检查表情符号(保留原有逻辑) code_point = ord(char) emoji_ranges = [ - (0x1F600, 0x1F64F), (0x1F300, 0x1F5FF), - (0x1F680, 0x1F6FF), (0x1F900, 0x1F9FF), - (0x1FA70, 0x1FAFF), (0x2600, 0x26FF), - (0x2700, 0x27BF) + (0x1F600, 0x1F64F), + (0x1F300, 0x1F5FF), + (0x1F680, 0x1F6FF), + (0x1F900, 0x1F9FF), + (0x1FA70, 0x1FAFF), + (0x2600, 0x26FF), + (0x2700, 0x27BF), ] - return any(start <= code_point <= end for start, end in emoji_ranges) \ No newline at end of file + return any(start <= code_point <= end for start, end in emoji_ranges)