fix: send system idle instead of tts stop to avoid Speaking→Listening race

Root cause: tts stop triggers Speaking→Listening, which calls
SendStartListening in HandleStateChangedEvent. idle arrives too late
and gets overridden. Fix: skip tts stop when idle is needed, go
Speaking→Idle directly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hailin 2026-04-06 09:30:55 -07:00
parent 16d8a744ac
commit eda88f83f3
1 changed files with 7 additions and 4 deletions

View File

@ -44,15 +44,18 @@ async def sendAudioMessage(conn: "ConnectionHandler", sentenceType, audios, text
# 发送结束消息(如果是最后一个文本)
if sentenceType == SentenceType.LAST:
await send_tts_message(conn, "stop", None)
conn.client_is_speaking = False
# Send system idle command if LLM requested it (e.g. antaf bridge unavailable)
if getattr(conn, 'send_idle_after_tts', False):
# Send system idle instead of tts stop — goes Speaking→Idle directly,
# avoids Speaking→Listening which triggers SendStartListening
conn.send_idle_after_tts = False
conn.client_is_speaking = False
await conn.websocket.send(
json.dumps({"type": "system", "command": "idle"})
)
conn.logger.bind(tag=TAG).info("Sent system idle to device")
conn.logger.bind(tag=TAG).info("Sent system idle to device (skip tts stop)")
else:
await send_tts_message(conn, "stop", None)
conn.client_is_speaking = False
if conn.close_after_chat:
await conn.close()