mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-23 03:19:41 +00:00
无快照时不回落共享连接态
This commit is contained in:
parent
4c04b9dd37
commit
9100e7ecd2
1 changed files with 10 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue