mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-23 03:19:41 +00:00
- audio_to_data 缓存键加入文件 mtime:regen 覆写 wav 后旧缓存自动失效,
并在 regen 后预编码新文件,唤醒回复不再播旧音频且延迟收益保留 - enhanced_prompt 缓存键补上 emoji_enabled 与 prompt 哈希: 同设备不同客户端(ESP32/digital-human)不再互相污染,改配置即时生效 - 删除 initialize 响应后的 tools/list 兜底补发:id=2 同连接复用 违反 JSON-RPC 与设备端严格递增约定(#3461/#3485),且兜不住任何场景
This commit is contained in:
parent
77be288c8e
commit
82d2acc78c
4 changed files with 16 additions and 7 deletions
|
|
@ -168,6 +168,9 @@ async def wakeupWordsResponse(conn: "ConnectionHandler"):
|
|||
f.write(wav_bytes)
|
||||
# 更新配置
|
||||
wakeup_words_config.update_wakeup_response(voice, file_path, result)
|
||||
# 覆写文件后 mtime 变化使旧缓存失效,此处立刻预编码新文件,
|
||||
# 下次唤醒直接命中缓存,编码成本不占用唤醒响应路径
|
||||
await audio_to_data(file_path, use_cache=True)
|
||||
finally:
|
||||
# 确保在任何情况下都释放锁
|
||||
if _wakeup_response_lock.locked():
|
||||
|
|
|
|||
|
|
@ -147,10 +147,6 @@ async def handle_mcp_message(
|
|||
logger.bind(tag=TAG).debug(
|
||||
f"客户端MCP服务器信息: name={name}, version={version}"
|
||||
)
|
||||
|
||||
# helloHandle 握手初期已并发预发 tools/list;此处再补一次作为兜底,client 收到两次也能正常处理
|
||||
asyncio.create_task(send_mcp_tools_list_request(conn))
|
||||
|
||||
return
|
||||
|
||||
elif msg_id == 2: # mcpToolsListID
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import os
|
||||
import asyncio
|
||||
import hashlib
|
||||
import threading
|
||||
from typing import Dict, Any, TYPE_CHECKING
|
||||
|
||||
|
|
@ -254,7 +255,12 @@ class PromptManager:
|
|||
if not self.base_prompt_template:
|
||||
return user_prompt
|
||||
|
||||
enhanced_cache_key = f"enhanced_prompt:{device_id}"
|
||||
# 缓存键须覆盖所有渲染输入:emoji 开关、设备 prompt 变更否则会命中过期提示词
|
||||
emoji_enabled = kwargs.get("emoji_enabled", True)
|
||||
prompt_hash = hashlib.md5(user_prompt.encode("utf-8")).hexdigest()[:8]
|
||||
enhanced_cache_key = (
|
||||
f"enhanced_prompt:{device_id}:{emoji_enabled}:{prompt_hash}"
|
||||
)
|
||||
cached_prompt = self.cache_manager.get(
|
||||
self.CacheType.DEVICE_PROMPT, enhanced_cache_key
|
||||
)
|
||||
|
|
|
|||
|
|
@ -310,8 +310,12 @@ async def audio_to_data(
|
|||
from core.utils.cache.manager import cache_manager
|
||||
from core.utils.cache.config import CacheType
|
||||
|
||||
# 生成缓存键,包含文件路径和编码类型
|
||||
cache_key = f"{audio_file_path}:{is_opus}"
|
||||
# 缓存键含 mtime:文件被原地覆写时旧缓存自动失效(如唤醒词回复重新 TTS),避免播到过期音频
|
||||
try:
|
||||
mtime = os.path.getmtime(audio_file_path)
|
||||
cache_key = f"{audio_file_path}:{mtime}:{is_opus}"
|
||||
except OSError:
|
||||
cache_key = f"{audio_file_path}:{is_opus}"
|
||||
|
||||
# 尝试从缓存获取结果
|
||||
if use_cache:
|
||||
|
|
|
|||
Loading…
Reference in a new issue