diff --git a/.gitignore b/.gitignore index d0709f97..675fb688 100644 --- a/.gitignore +++ b/.gitignore @@ -155,3 +155,4 @@ main/manager-web/node_modules # model files main/xiaozhi-server/models/SenseVoiceSmall/model.pt main/xiaozhi-server/models/sherpa-onnx* +my_wakeup_words.mp3 diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index c9a52b12..682ccf8f 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 cc968862..4583a6e3 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()