From 3e7c200a0b0c9f5747b9a2258158dfaeb4bddcad Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Mon, 9 Jun 2025 12:35:25 +0800 Subject: [PATCH] =?UTF-8?q?update:=E4=BC=98=E5=8C=96=E5=B8=A6=E6=9C=89?= =?UTF-8?q?=E6=96=B9=E6=8B=AC=E5=8F=B7=E7=9A=84=E5=AD=97=E7=AC=A6=E8=AF=AD?= =?UTF-8?q?=E9=9F=B3=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiaozhi-server/core/handle/helloHandle.py | 4 +++ main/xiaozhi-server/core/utils/textUtils.py | 34 +++++++++++++------ 2 files changed, 27 insertions(+), 11 deletions(-) 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)