From 9100e7ecd20b6cae32c827bd0947afd8c0573f20 Mon Sep 17 00:00:00 2001 From: Sakura-RanChen <1908198662@qq.com> Date: Wed, 18 Nov 2026 15:14:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0=E5=BF=AB=E7=85=A7=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E5=9B=9E=E8=90=BD=E5=85=B1=E4=BA=AB=E8=BF=9E=E6=8E=A5=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/connection.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index f14f8ec62..0ccc99e7b 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -1122,13 +1122,19 @@ class ConnectionHandler: # 仅在该说话人首次出现时把身份注入 system,之后靠对话历史首轮保留, # 避免每轮在 system 重复出现名字诱导模型反复称呼 speaker_for_system = None - # 展示名优先取本轮 speaker 快照:manual 模式下两轮 chat 线程可能并发, - # conn.current_speaker 已被下一轮覆盖,连接态仅在无快照路径作兜底 + # 展示名只取本轮数据(声纹快照 → query JSON),不读并发下会被覆盖的连接态 cs = "" if speaker is not None: cs = (speaker.name or "").strip() - if not cs: - cs = (self.current_speaker or "").strip() + if not cs and depth == 0 and query: + q = query.strip() + if q.startswith("{") and q.endswith("}"): + try: + parsed = json.loads(q) + if isinstance(parsed, dict): + cs = (parsed.get("speaker") or "").strip() + except (json.JSONDecodeError, TypeError, ValueError): + pass if cs and cs != UNKNOWN_SPEAKER_NAME and cs not in self.system_introduced_speakers: self.system_introduced_speakers.add(cs) speaker_for_system = cs