From 64816e9183121d2020ba62c2dde36882cfed458f Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Tue, 25 Mar 2025 23:46:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=94=A4=E9=86=92=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=98=AF=E4=B8=80=E4=B8=AA=E7=A9=BA=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/connection.py | 4 +++- main/xiaozhi-server/core/handle/helloHandle.py | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index c9a52b120..682ccf8fe 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -323,7 +323,9 @@ class ConnectionHandler: self.dialogue.put(Message(role="user", content=query)) # Define intent functions - functions = self.func_handler.get_functions() + functions = None + if hasattr(self, 'func_handler'): + functions = self.func_handler.get_functions() response_message = [] processed_chars = 0 # 跟踪已处理的字符位置 diff --git a/main/xiaozhi-server/core/handle/helloHandle.py b/main/xiaozhi-server/core/handle/helloHandle.py index cc9688624..4583a6e3b 100644 --- a/main/xiaozhi-server/core/handle/helloHandle.py +++ b/main/xiaozhi-server/core/handle/helloHandle.py @@ -45,12 +45,14 @@ async def checkWakeupWords(conn, text): def getWakeupWordFile(file_name): for file in os.listdir(WAKEUP_CONFIG["dir"]): - if "my_"+file_name in file: - return f"config/assets/{file}" + if file.startswith("my_" + file_name): + """避免缓存文件是一个空文件""" + if os.stat(f"config/assets/{file}").st_size > (5 * 1024): + return f"config/assets/{file}" """查找config/assets/目录下名称为wakeup_words的文件""" for file in os.listdir(WAKEUP_CONFIG["dir"]): - if file_name in file: + if file.startswith(file_name): return f"config/assets/{file}" return None @@ -64,9 +66,9 @@ async def wakeupWordsResponse(conn): file_type = os.path.splitext(tts_file)[1] if file_type: file_type = file_type.lstrip('.') - old_file = getWakeupWordFile("my_" +WAKEUP_CONFIG["file_name"]) + old_file = getWakeupWordFile("my_" + WAKEUP_CONFIG["file_name"]) if old_file is not None: os.remove(old_file) """将文件挪到"wakeup_words.mp3""" - shutil.move(tts_file, WAKEUP_CONFIG["dir"] + "my_" +WAKEUP_CONFIG["file_name"] + "." + file_type) + shutil.move(tts_file, WAKEUP_CONFIG["dir"] + "my_" + WAKEUP_CONFIG["file_name"] + "." + file_type) WAKEUP_CONFIG["create_time"] = time.time()