1.修复关机时播报关机语音后还会播报半句正在充电的BUG。2.优化长对话模式下短按两次ai键后无法继续对话的情况。3.修改低电量提醒为10分钟一次。4.优化单对话模式下短...
authorTimekeeperPL <1624952103@qq.com>
Mon, 22 Jun 2026 09:49:46 +0000 (17:49 +0800)
committerTimekeeperPL <1624952103@qq.com>
Mon, 22 Jun 2026 09:49:46 +0000 (17:49 +0800)
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/products/configs/k8v3/default_config.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/products/product_k8v3.ini
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_buttons.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_key_router.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_mode_strategy.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_notify.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_io.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_media.py

index 06c8e48..50f0d98 100644 (file)
@@ -96,7 +96,7 @@ SIGNAL_WEAK_CSQ = 10  # 0≤CSQ<此值 → signal=weak(REQ-ERR-02)
 # SoC 门限:仅低电提示/LED 空电闪(REQ-BAT-02/03);关机见 VBATT_EMPTY_MV
 BATTERY_LOW_SOC_PERCENT = 25       # <25% 低电语音
 BATTERY_EMPTY_SOC_PERCENT = 5      # <5% LED 空电态;不单独触发关机
-BATTERY_LOW_WARN_INTERVAL_MS = 300000  # 低电语音间隔 5min
+BATTERY_LOW_WARN_INTERVAL_MS = 600000  # 低电语音间隔 10min
 # 充电 SoC 实时映射时,低于此值不播「已满」TTS(防低电后立即误报;须配合 is_charge_full)
 BATTERY_CHARGE_FULL_TTS_MIN_SOC = 50
 BATTERY_EMPTY_FLASH_COUNT = 3
index 1187942..f560d59 100644 (file)
@@ -193,7 +193,8 @@ class AI_dev(Abstract):
         print("AI_dev:AI_dev_timer")
         self.aud = audio.Audio(0)
         self.Low_power_warning_flag = 0
-        self._low_warn_last_ms = 0
+        self._low_warn_next_ms = 0
+        self._low_warn_os_timer = osTimer()
         self._empty_shutdown_done = 0
         self.VC_TTS_volume = EventMesh.publish("get_storage_config", "VC_TTS_volume")
         if self.VC_TTS_volume is None:
@@ -295,6 +296,10 @@ class AI_dev(Abstract):
                     pass
                 EventMesh.publish("audio_montage_play",["R_CHARGE_IN.mp3"])
             self.Low_power_warning_flag  = 0
+            try:
+                self._low_warn_reset()
+            except Exception:
+                pass
             try:
                 self._empty_shutdown_done = 0
             except Exception:
@@ -907,6 +912,8 @@ class AI_dev(Abstract):
         EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_dev_timer_event})  
     def _battery_empty_shutdown_seq(self):
         """REQ-BAT-03:红快闪 3 次 → 灭灯 → 关机提示音 → 关机(btn 线程执行)。"""
+        self._shutting_down = 1
+        self._montage_defer = []
         try:
             EventMesh.publish("battery_priority_mute_vc")
         except Exception:
@@ -932,6 +939,47 @@ class AI_dev(Abstract):
         except Exception:
             pass
 
+    def _low_warn_reset(self):
+        self._low_warn_next_ms = 0
+        try:
+            self._low_warn_os_timer.stop()
+        except Exception:
+            pass
+
+    def _low_warn_timer_cb(self, *args, **kwargs):
+        EventMesh.publish("publish_AI_btnInfo", {"func": self._low_warn_tick})
+
+    def _low_warn_tick(self, soc=None):
+        """低电语音:首次立即播,之后 osTimer 每 10min 触发;10s 轮询作到期兜底。"""
+        if self.usb_status != 0:
+            return
+        if soc is None:
+            try:
+                soc = self.get_battery()
+            except Exception:
+                soc = None
+        try:
+            low_soc = int(_BatteryCfg.instance().low_soc)
+        except Exception:
+            low_soc = 25
+        if soc is None or soc >= low_soc:
+            self._low_warn_reset()
+            return
+        now = utime.ticks_ms()
+        interval_ms = cfg_int("BATTERY_LOW_WARN_INTERVAL_MS", 600000)
+        next_ms = int(getattr(self, "_low_warn_next_ms", 0) or 0)
+        if next_ms and utime.ticks_diff(now, next_ms) < 0:
+            return
+        self._low_warn_next_ms = utime.ticks_add(now, interval_ms)
+        print("[BAT] low warn soc={} interval_ms={}".format(soc, interval_ms))
+        EventMesh.publish("audio_montage_play", ["Low_power_warning.mp3"])
+        try:
+            delay = max(50, interval_ms)
+            self._low_warn_os_timer.stop()
+            self._low_warn_os_timer.start(delay, 0, self._low_warn_timer_cb)
+        except Exception:
+            pass
+
     def AI_dev_timer_event(self):
         #EventMesh.publish("audio_montage_play",["liuliangtishi.mp3"])
         EventMesh.publish("send_power_init_data")
@@ -992,7 +1040,6 @@ class AI_dev(Abstract):
             low_soc = int(_bcfg.low_soc)
         except Exception:
             low_soc = 25
-        warn_interval_ms = cfg_int("BATTERY_LOW_WARN_INTERVAL_MS", 300000)
         if self.usb_status == 0:
             if _bcfg.should_shutdown_empty(Vbatt):
                 if getattr(self, "_empty_shutdown_done", 0) == 0:
@@ -1001,19 +1048,10 @@ class AI_dev(Abstract):
                         Vbatt, soc, _bcfg.empty_mv))
                     EventMesh.publish("publish_AI_btnInfo", {"func": self._battery_empty_shutdown_seq})
             elif soc is not None and soc < low_soc:
-                if voice_record_satrt_flag == 0:
-                    try:
-                        now = utime.ticks_ms()
-                        last = getattr(self, "_low_warn_last_ms", 0)
-                        if (not last) or utime.ticks_diff(now, last) >= warn_interval_ms:
-                            self._low_warn_last_ms = now
-                            print("[BAT] low warn soc={} interval_ms={}".format(soc, warn_interval_ms))
-                            EventMesh.publish("audio_montage_play", ["Low_power_warning.mp3"])
-                    except Exception:
-                        pass
+                self._low_warn_tick(soc)
             else:
                 try:
-                    self._low_warn_last_ms = 0
+                    self._low_warn_reset()
                     self._empty_shutdown_done = 0
                 except Exception:
                     pass
@@ -1091,6 +1129,8 @@ class AI_dev(Abstract):
 
     def _shutdown_tone_play_and_powerdown(self):
         """关机提示音:先断 VC TTS,再播 zhengzaiguanji,最后断电。"""
+        self._shutting_down = 1
+        self._montage_defer = []
         self._persist_vc_mode_before_powerdown()
         try:
             EventMesh.publish("battery_priority_mute_vc")
@@ -1112,6 +1152,8 @@ class AI_dev(Abstract):
         Power.powerDown()
 
     def audio_montage_play(self,event,msg):
+        if getattr(self, "_shutting_down", 0) and not self._audio_is_battery_priority(msg):
+            return
         self.wakeup_BT()
         bat_pri = self._audio_is_battery_priority(msg)
         if bat_pri:
index c236c84..eed5aff 100644 (file)
@@ -105,16 +105,20 @@ class KeyRouter(object):
         if getattr(vc, "VC_record_state_flag", 0) == 0:
             return False
         min_ms = cfg_int("PTT_MIN_RECORD_MS", 1200)
-        tts = cfg_attr("PTT_RECORD_TOO_SHORT_TTS", "录音时间太短,请按住圆形按钮说话") or "录音时间太短,请按住圆形按钮说话"
-        t_open = int(getattr(vc, "_ptt_begin_ms", 0) or 0)
+        tts = vc._vc_ptt_too_short_text()
+        t_open = int(getattr(vc, "_ptt_record_open_ms", 0) or 0)
+        if not t_open:
+            t_open = int(getattr(vc, "_ptt_begin_ms", 0) or 0)
         if not t_open or utime is None:
             return False
         try:
-            if utime.ticks_diff(utime.ticks_ms(), t_open) >= min_ms:
+            hold_ms = utime.ticks_diff(utime.ticks_ms(), t_open)
+            if hold_ms >= min_ms:
                 return False
         except Exception:
             return False
         try:
+            print("[PTT] hold too short hold_ms={} min_ms={}".format(hold_ms, min_ms))
             vc._ptt_abort_short_record(tts)
         except Exception:
             pass
index d865b93..4f82516 100644 (file)
@@ -43,7 +43,9 @@ class PTTStrategy(VCModeStrategy):
         if getattr(vc, "trans_flag", 0) == 1:
             vc.Close()
             EventMesh.publish("start_voice_record", 4)
-        vc.AI_key_long_press_flag = 1
+        # 录音中重复按下勿清 long_press_flag,否则松手误走 release_short_no_long 不停麦
+        if getattr(vc, "VC_record_state_flag", 0) == 0:
+            vc.AI_key_long_press_flag = 0  # 真开录后由 Speech_Start_now 置 1
         vc._ptt_idle_latch = 0
         vc._ptt_short_press_stop = 0
         vc.ptt_begin()
index d197bb7..11ec771 100644 (file)
@@ -89,7 +89,7 @@ class NotifyScheduler(object):
         ):
             plan.append({"op": OP_LONG_UPLINK})
 
-        tts = getattr(vc, "AI_TTS_str", "") or ""
+        tts = str(getattr(vc, "AI_TTS_str", "") or "").strip()
         url = getattr(vc, "AI_new_voice_url", "") or ""
         alarm = getattr(vc, "alarm_play_flag", 0) == 1
         music = getattr(vc, "music_play_flag", 0) == 1
index f6bcb1f..0d99fc7 100644 (file)
@@ -12,7 +12,7 @@ from vc_notify import (
     OP_LONG_UPLINK, OP_ALARM_VOICE, OP_VOICE_URL, OP_SYNTHESIS,
     OP_SYNTHESIS_HIS_TIMER, OP_SYNTHESIS_WAIT_TIMER, OP_SYNTHESIS_WAIT_SINGLE,
     OP_SYNTHESIS_VOICE_TIMER, OP_SYNTHESIS_MUSIC_TIMER, OP_IDLE_UPLINK,
-    OP_PTT_ROUND, OP_UPLOAD_TONE,
+    OP_PTT_ROUND, OP_UPLOAD_TONE, TTS_KIND_PROMPT,
 )
 from vc_mode_strategy import strategy_for_mode
 from vc_utils import (
@@ -49,6 +49,8 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
         try:
             self._ptt_idle_latch = 0
             self._ptt_short_press_stop = 0
+            self._ptt_stale_prompt_drop = 0
+            self._ptt_suppress_late_tts = 0
             self._ptt_record_open_ms = 0
             self._ptt_interrupt_active = 0
             self._ptt_led_lock_listening = 0
@@ -464,10 +466,11 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
             if getattr(self, "VC_record_state_flag", 0) != 0 and self._vc_vad_uplink_stop_eligible():
                 print("[VC][ASR] merge window end -> stop uplink")
                 self.request_uplink_stop("asr.completed/merge_timeout")
-                # merge çª\97ç»\93æ\9d\9fï¼\88æ\97 ç»­è¯´ï¼\89ï¼\9aæ \87è®° think å¾\85æ\92­ï¼\8cå\9c¨å½\95é\9f³çº¿ç¨\8b gate drain å\90\8eæ\89§è¡\8c
+                # merge çª\97ç»\93æ\9d\9fï¼\88æ\97 ç»­è¯´ï¼\89ï¼\9aæ\8c\82 think å¾\85æ\92­
                 try:
-                    if getattr(self, "_asr_completed_tone_done", 0) == 0:
-                        self._asr_completed_tone_done = 1
+                    if hasattr(self, "_vc_arm_think_tone_pending"):
+                        self._vc_arm_think_tone_pending()
+                    elif getattr(self, "_asr_completed_tone_done", 0) == 0:
                         self._think_tone_pending = 1
                 except Exception:
                     pass
@@ -477,8 +480,10 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
     def _vc_local_vad_asr_fallback_tick(self):
         """local_vad endpoint 模式下 fallback:若本地 VAD 未检测到语音终点,但服务端 ASR
         已有结果且超过 merge 窗仍无新结果,视为句末,主动发 audio.completed。
-        防止 VAD 灵敏度不足时录音无限持续直到 turn_cap。"""
+        防止 VAD 灵敏度不足时长对话录音无限持续直到 turn_cap。PTT 仅松手 end_speech,不走此路径。"""
         try:
+            if not self._vc_is_long_dialogue_mode():
+                return
             if not self._vc_local_vad_endpoint():
                 return
             if getattr(self, "VC_record_state_flag", 0) < 2:
@@ -828,6 +833,15 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
         """打断后已停播/开麦:迟到的 tts.completed 不参与 await_played / play_end。"""
         try:
             if self._vc_is_ptt_mode() and not self._vc_tts_playback_active():
+                # 松手等 ASR/LLM:勿因上一轮 cancel 残留的 drop 标志误丢对话 TTS
+                if getattr(self, "_ptt_await_server", 0) == 1:
+                    return bool(
+                        getattr(self, "VC_record_state_flag", 0)
+                        or getattr(self, "_ptt_interrupt_active", 0)
+                        or getattr(self, "_vc_serial_canceling", 0)
+                        or getattr(self, "_ptt_pending_arm", 0)
+                        or getattr(self, "AI_key_long_press_flag", 0)
+                    )
                 return bool(
                     getattr(self, "VC_record_state_flag", 0)
                     or getattr(self, "_ptt_interrupt_active", 0)
@@ -857,6 +871,41 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
         except Exception:
             return False
 
+    def _ptt_release_hold_ms(self):
+        """本轮 PTT 按住时长;松手后 _ptt_record_open_ms 可能已清,用 _ptt_begin_ms 兜底。"""
+        try:
+            t_open = int(getattr(self, "_ptt_record_open_ms", 0) or 0)
+            if not t_open:
+                t_open = int(getattr(self, "_ptt_begin_ms", 0) or 0)
+            if not t_open:
+                return 0
+            return utime.ticks_diff(utime.ticks_ms(), t_open)
+        except Exception:
+            return 0
+
+    def _ptt_release_should_await_server(self):
+        """PTT 松手后应等云端 ASR/LLM,勿因 ASR 迟到立刻判无声 cancel。
+
+        设计:按住合法时长 / 本地 VAD / 流式 partial 均视为「可能有话」→ thinking 等回复。
+        仅确无上述信号时才走 ptt_release/silent(idle + cancel,不播没听清)。
+        """
+        if self._ptt_release_has_speech():
+            return True
+        try:
+            if getattr(self, "_turn_has_asr_result", 0):
+                return True
+            if getattr(self, "_vc_turn_had_speech", 0):
+                return True
+            hold_ms = self._ptt_release_hold_ms()
+            min_ms = cfg_int("PTT_MIN_RECORD_MS", 1200)
+            if hold_ms > 0 and hold_ms < min_ms:
+                return False
+            if hold_ms >= min_ms:
+                return True
+        except Exception:
+            pass
+        return False
+
     def _long_dialogue_should_drop_inbound_tts(self):
         """长对话打断窗口:丢弃迟到 TTS 帧 / 禁止起播。"""
         if not self._vc_is_long_dialogue_mode():
@@ -1345,6 +1394,8 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
                 EventMesh.publish(
                     "publish_AI_btnInfo", {"func": self.AI_client_new_voice})
             elif op == OP_SYNTHESIS:
+                if not str(getattr(self, "AI_TTS_str", "") or "").strip():
+                    continue
                 EventMesh.publish(
                     "publish_AI_btnInfo", {"func": self.AI_client_VC_synthesis})
             elif op == OP_SYNTHESIS_HIS_TIMER:
@@ -1417,6 +1468,10 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
 
     def _ptt_abort_short_record(self, tts_str):
         """PTT 录音过短:cancel + notify TTS + idle。"""
+        try:
+            self._vc_turn_bump("ptt_short_record")
+        except Exception:
+            pass
         try:
             self.AI_key_long_press_flag = 0
             self._ptt_defer_speech_until_asr = 0
@@ -1448,7 +1503,7 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
             pass
         try:
             if tts_str:
-                EventMesh.publish("play_tts", [tts_str, 0, "prompt"])
+                self._vc_play_prompt_notify(tts_str, reason="ptt_short_record")
         except Exception:
             pass
         try:
@@ -1515,6 +1570,9 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
 
     def _vc_handle_asr_empty_ptt(self, hint, reason="asr.completed"):
         """单对话:松手无声→idle+cancel;服务端 asr.completed 空文本→播没听清。"""
+        # 松手后 deferred 等 ASR:云端仍空且本地 VAD 无人声 → 等同无声松手,不播没听清
+        if reason == "asr.completed" and not getattr(self, "_vc_turn_had_speech", 0):
+            reason = "ptt_release/silent"
         try:
             self._ptt_await_server = 0
             self._ptt_await_since_ms = 0
@@ -1553,7 +1611,7 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
         except Exception:
             pass
         try:
-            EventMesh.publish("play_tts", [hint, 0, "prompt"])
+            self._vc_play_prompt_notify(hint, reason="asr.empty")
         except Exception:
             pass
         try:
@@ -1778,9 +1836,13 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
                 self._vc_turn_bump("ptt_short_stop")
             self.is_ruppt_tts = 1
             self._drop_tts_audio = 1
+            self._ptt_suppress_late_tts = 1
             self._ptt_interrupt_active = 0
             self._ptt_led_lock_listening = 0
             self.fsm.await_played = False
+            self._vc_ptt_abort_play_end_wait()
+            if hasattr(self, "_vc_tts_rx_counters_reset"):
+                self._vc_tts_rx_counters_reset()
         except Exception:
             pass
         try:
@@ -1910,6 +1972,8 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
             self._vc_endpoint_hangover_until = 0
             self._server_vad_silence = 0
             self._vc_asr_continue_merge = 0
+            self._ptt_audio_created = 0
+            self._vc_ld_awaiting_reply = 0
             self.fsm.await_played = False
         except Exception:
             pass
@@ -1980,6 +2044,30 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
         """单对话 PTT 松手:上行录音中时 end_speech,未录上时 abort 提示。"""
         if not self._vc_is_ptt_mode():
             return
+        # 正在录音:松手必 end_speech(PTT 语义),不依赖 AI_key_long_press_flag
+        if getattr(self, "VC_record_state_flag", 0) != 0:
+            try:
+                from vc_key_router import KeyRouter
+                if KeyRouter.ptt_release_after_long_press(self):
+                    self.AI_key_long_press_flag = 0
+                    return
+            except Exception:
+                pass
+            try:
+                gap = cfg_int("PTT_RELEASE_END_SPEECH_DELAY_MS", 200)
+                if gap > 0:
+                    utime.sleep_ms(gap)
+            except Exception:
+                pass
+            print("[PTT] release end_speech asr_str={!r} rec={}".format(
+                self.AI_ASR_str, getattr(self, "VC_record_state_flag", -1)))
+            self.AI_client_VC_end_speech()
+            try:
+                self._ptt_record_open_ms = 0
+            except Exception:
+                pass
+            self.AI_key_long_press_flag = 0
+            return
         if self.AI_key_long_press_flag == 0:
             try:
                 from vc_key_router import KeyRouter
@@ -1994,30 +2082,8 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
             except Exception:
                 pass
         if self.AI_key_long_press_flag == 1:
-            try:
-                from vc_key_router import KeyRouter
-                # 先判时长:录上了但太短 → abort 提示
-                if KeyRouter.ptt_release_after_long_press(self):
-                    return
-            except Exception:
-                pass
-            if getattr(self, "VC_record_state_flag", 0) != 0:
-                try:
-                    gap = cfg_int("PTT_RELEASE_END_SPEECH_DELAY_MS", 200)
-                    if gap > 0:
-                        utime.sleep_ms(gap)
-                except Exception:
-                    pass
-                print("[PTT] release end_speech asr_str={!r} rec={}".format(
-                    self.AI_ASR_str, getattr(self, "VC_record_state_flag", -1)))
-                self.AI_client_VC_end_speech()
-                try:
-                    self._ptt_record_open_ms = 0
-                except Exception:
-                    pass
-            else:
-                # 没录上(pending arm / cancel wait / session 未就绪):统一 abort + 提示
-                self._vc_handle_release_no_record_ptt()
+            # 真开录标记仍在但硬件未录上(cancel 等待等)
+            self._vc_handle_release_no_record_ptt()
             return
         try:
             if getattr(self, "_ptt_short_press_stop", 0) == 1:
@@ -2044,7 +2110,7 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
         pass
 
     def _vc_handle_release_no_record_ptt(self):
-        """PTT press 后 release 时没录上:清 cancel_wait + 播提示 + idle(不二次发 cancel)。"""
+        """PTT 按下后未真开录就松手:清 pending + idle(不是「录音太短」)。"""
         try:
             self.AI_key_long_press_flag = 0
             self._ptt_defer_speech_until_asr = 0
@@ -2059,23 +2125,38 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
             self._ptt_interrupt_active = 0
         except Exception:
             pass
-        print("[PTT] release no record -> cancel pending + notify")
+        print("[PTT] release no record -> idle (skip too_short)")
         try:
-            tts = cfg_attr("PTT_RECORD_TOO_SHORT_TTS",
-                           "录音时间太短,请按住圆形按钮说话") or "录音时间太短,请按住圆形按钮说话"
-            EventMesh.publish("play_tts", [tts, 0, "prompt"])
-        except Exception:
-            pass
-        try:
-            self._vc_publish_led("idle", "ptt_short_record")
+            self._vc_publish_led("idle", "ptt_no_record")
         except Exception:
             pass
 
     def _ptt_should_drop_inbound_tts(self):
-        """单对话打断窗口:丢弃迟到 TTS 帧 / 禁止起播。"""
+        """单对话:是否丢弃下行 TTS 帧/事件(prompt 与 cancel 残留)。"""
         if not self._vc_is_ptt_mode():
             return False
         try:
+            # 松手等对话回复:允许对话 TTS(设计稿 thinking→playing)
+            if getattr(self, "_ptt_await_server", 0) == 1:
+                if not getattr(self, "_ptt_interrupt_active", 0) and not getattr(
+                    self, "_vc_serial_canceling", 0
+                ):
+                    return False
+            k = (
+                getattr(self, "_pending_tts_kind", "")
+                or getattr(self, "_last_tts_kind", "")
+                or ""
+            )
+            # 短按停播 / cancel 后:丢弃 cancel 前在途整轮下行(至有效松手或新 prompt)
+            if getattr(self, "_ptt_suppress_late_tts", 0) == 1:
+                return True
+            # prompt notify 专用:开录中或替换后丢弃迟到 notify
+            if k == TTS_KIND_PROMPT:
+                if getattr(self, "VC_record_state_flag", 0) != 0:
+                    return True
+                if getattr(self, "_ptt_stale_prompt_drop", 0) == 1:
+                    return True
+            # 打断/cancel 窗口
             if getattr(self, "_drop_tts_audio", 0) == 1:
                 return True
             if getattr(self, "is_ruppt_tts", 0) == 1:
@@ -2089,6 +2170,32 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
         except Exception:
             pass
         return False
+
+    def _vc_ptt_drop_server_event(self, ev, where=""):
+        """PTT 丢弃迟到下行事件;返回 True 表示已丢弃。"""
+        try:
+            stale = getattr(self, "_VC_STALE_DROP_EVENTS", None)
+            if stale is None:
+                from vc_session_io import VCSessionIoMixin
+                stale = VCSessionIoMixin._VC_STALE_DROP_EVENTS
+            if ev not in stale:
+                return False
+            if not self._ptt_should_drop_inbound_tts():
+                return False
+            print("[VC][DROP] {} ev={}".format(where or "server", ev))
+            if ev == "tts.completed":
+                self._vc_ptt_abort_play_end_wait()
+            return True
+        except Exception:
+            return False
+
+    def _vc_ptt_clear_late_tts_suppress(self, reason=""):
+        """有效对话轮次开始:允许对话 TTS 下行。"""
+        try:
+            self._ptt_suppress_late_tts = 0
+            self._ptt_stale_prompt_drop = 0
+        except Exception:
+            pass
     def _ptt_should_skip_remote_playback(self):
         return self._ptt_should_drop_inbound_tts()
     def _ptt_enter_interrupt_arm(self, bump_gen=True):
@@ -2425,6 +2532,10 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
                 self.fsm.last_tts_completed_ms = 0
             except Exception:
                 pass
+            self._tts_play_end_out_stuck_ms = 0
+            self._tts_play_end_last_out = 0
+            if hasattr(self, "_vc_tts_rx_counters_reset"):
+                self._vc_tts_rx_counters_reset()
         except Exception:
             pass
 
@@ -2468,6 +2579,12 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
             pass
         self._vc_ptt_abort_play_end_wait()
 
+        try:
+            if self._vc_cancel_prompt_notify_in_flight("ptt_begin"):
+                self._vc_turn_bump("ptt_begin/prompt")
+        except Exception:
+            pass
+
         t0 = 0
         try:
             t0 = utime.ticks_ms()
@@ -2874,6 +2991,8 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
         self._ptt_led_lock_listening = 0
         self._ptt_idle_latch = 0
         self._ptt_short_press_stop = 0
+        self._ptt_stale_prompt_drop = 0
+        self._ptt_suppress_late_tts = 0
         self._long_dialogue_key_arm = 0
         self._vc_key_restart_arm = 0
         # AI 键短/长按开录:置位后等 server.started / asr.started(或会话已 started)再播 start.mp3
@@ -3855,6 +3974,140 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
         """遗留 montage(audio.bin 内 key_prompt);K8 量产不用,请用 RECORD_START_TONE。"""
         EventMesh.publish("audio_montage_play", ["key_prompt.mp3"])
 
+    def _vc_ptt_too_short_text(self):
+        try:
+            t = cfg_attr("PTT_RECORD_TOO_SHORT_TTS", None)
+            t = str(t or "录音时间太短,请按住圆形按钮说话").strip()
+            return t or "录音时间太短,请按住圆形按钮说话"
+        except Exception:
+            return "录音时间太短,请按住圆形按钮说话"
+
+    def _vc_prompt_notify_in_flight(self):
+        """提示 notify 是否在播/待发 synthesis。"""
+        try:
+            k = getattr(self, "_pending_tts_kind", "") or getattr(self, "_last_tts_kind", "") or ""
+            if k != TTS_KIND_PROMPT:
+                return False
+            if getattr(self, "VC_Play_flag", 0) == 1:
+                return True
+            if getattr(self, "_tts_pending", 0) == 1:
+                return True
+            if str(getattr(self, "AI_TTS_str", "") or "").strip():
+                return True
+        except Exception:
+            pass
+        return False
+
+    def _vc_cancel_prompt_notify_in_flight(self, reason="prompt_cancel"):
+        """终止在途 prompt notify:硬关下行+清队列,避免双路 TTS 叠播电音。"""
+        try:
+            if not self._vc_prompt_notify_in_flight():
+                return False
+        except Exception:
+            return False
+        was_playing = False
+        try:
+            was_playing = getattr(self, "VC_Play_flag", 0) == 1
+        except Exception:
+            pass
+        try:
+            self._tts_pending = 0
+            self._tts_pending_ms = 0
+        except Exception:
+            pass
+        try:
+            if hasattr(self, "_vc_downlink_stop_playback"):
+                self._vc_downlink_stop_playback(reason, force_hard=1)
+            elif getattr(self, "VC_Play_flag", 0) == 1:
+                self.VC_Play_End()
+        except Exception:
+            pass
+        try:
+            if hasattr(self, "_vc_pcm_discard_soft_stopped_handle"):
+                self._vc_pcm_discard_soft_stopped_handle()
+        except Exception:
+            pass
+        try:
+            if getattr(self, "AI_audio_queue", None) is not None:
+                if self.AI_audio_queue.empty() != True:
+                    self.AI_audio_queue.clear()
+        except Exception:
+            pass
+        try:
+            if hasattr(self, "_vc_tts_rx_counters_reset"):
+                self._vc_tts_rx_counters_reset()
+        except Exception:
+            pass
+        try:
+            if was_playing:
+                self.fsm.await_played = False
+        except Exception:
+            pass
+        try:
+            self._ptt_stale_prompt_drop = 1
+            self._drop_tts_audio = 1
+        except Exception:
+            pass
+        try:
+            if (
+                getattr(self, "AI_client_VC_isconnect", 0) == 1
+                and getattr(self, "_vc_session_started", 0) == 1
+            ):
+                self._vc_send_protocol_cancel(reason or "prompt_cancel")
+        except Exception:
+            pass
+        print("[VC][notify] cancel in-flight reason={}".format(reason or "-"))
+        return True
+
+    def _vc_play_prompt_notify(self, text, reason=""):
+        """提示类 notify:会话已连接时走 synthesis,避免 play_tts 断 WS + play_pcm 复用无声。"""
+        tts_str = str(text or "").strip()
+        if not tts_str:
+            return
+        connected = False
+        try:
+            connected = (
+                getattr(self, "Close_flag", 0) == 0
+                and getattr(self, "AI_client_VC_isconnect", 0) == 1
+                and getattr(self, "_vc_session_started", 0) == 1
+            )
+        except Exception:
+            pass
+        if connected:
+            try:
+                self._vc_cancel_prompt_notify_in_flight(reason or "notify_replace")
+            except Exception:
+                pass
+            try:
+                self._pending_tts_kind = TTS_KIND_PROMPT
+                self._last_tts_kind = TTS_KIND_PROMPT
+            except Exception:
+                pass
+            try:
+                from vc_media_arb import MediaArbiter
+                MediaArbiter.before_notify(self)
+            except Exception:
+                pass
+            try:
+                self._drop_tts_audio = 0
+                self.is_ruppt_tts = 0
+                self._ptt_interrupt_active = 0
+                self._vc_serial_canceling = 0
+                self._ptt_pending_arm = 0
+                self._ptt_stale_prompt_drop = 0
+                self._ptt_suppress_late_tts = 0
+                print("TTS音频为:{},语音下发地址为:{}".format(
+                    tts_str, getattr(self, "AI_new_voice_url", "") or ""))
+                self.request_send_synthesis(tts_str)
+                print("[VC][notify] prompt synthesis reason={}".format(reason or "-"))
+            except Exception as e:
+                usys.print_exception(e)
+            return
+        try:
+            EventMesh.publish("play_tts", [tts_str, 0, "prompt"])
+        except Exception:
+            pass
+
     def _ptt_play_idle_hint(self):
         """PTT idle 短按:notify 话术提醒(对齐 k8 PTT_HINT,非 KEY_PRESS 本地音)。"""
         try:
@@ -3866,7 +4119,7 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
             tts_str = str(tts_str or "").strip()
             if not tts_str:
                 return
-            EventMesh.publish("play_tts", [tts_str, 0, "prompt"])
+            self._vc_play_prompt_notify(tts_str, reason="ptt_idle_hint")
         except Exception as e:
             usys.print_exception(e)
     def VC_error(self, event, msg):#错误播报
index 8730b18..668c3e2 100644 (file)
@@ -54,6 +54,9 @@ class VCSessionIoMixin:
             "broken pipe",
             "connection refused",
             "timeout",
+            "synthesis text cannot be empty",
+            "合成文本不能为空",
+            "文本不能为空",
         ):
             if pat in low:
                 return None
@@ -155,7 +158,14 @@ class VCSessionIoMixin:
             except Exception:
                 pass
             if self._vc_is_ptt_mode():
-                if getattr(self, "VC_record_state_flag", 0) != 0:
+                if (
+                    getattr(self, "_ptt_await_server", 0) == 1
+                    and getattr(self, "VC_record_state_flag", 0) == 0
+                    and not getattr(self, "_vc_serial_canceling", 0)
+                    and not getattr(self, "_ptt_pending_arm", 0)
+                ):
+                    print("[ORCH] stale canceled (ptt await_server -> keep dialog tts)")
+                elif getattr(self, "VC_record_state_flag", 0) != 0:
                     try:
                         self._drop_tts_audio = 1
                         if getattr(self, "AI_audio_queue", None) is not None:
@@ -211,6 +221,11 @@ class VCSessionIoMixin:
 
     def _vc_dispatch_server_event(self, ev, jsload_data=None):
         """recv 线程:仅入编排队列,不在此修改 FSM。tts.started 走高优队列减小播放延迟。"""
+        try:
+            if hasattr(self, "_vc_ptt_drop_server_event") and self._vc_ptt_drop_server_event(ev, "dispatch"):
+                return
+        except Exception:
+            pass
         gen = self._vc_turn_current()
         priority = 1 if ev == "tts.started" else 0
         self._vc_enqueue_btn(
@@ -228,7 +243,10 @@ class VCSessionIoMixin:
     def request_send_audio_played(self):
         EventMesh.publish("publish_AI_btnInfo", {"func": self.AI_client_VC_audio_played})
     def request_send_synthesis(self, text):
-        self.AI_TTS_str = text
+        t = str(text or "").strip()
+        if not t:
+            return
+        self.AI_TTS_str = t
         EventMesh.publish("publish_AI_btnInfo", {"func": self.AI_client_VC_synthesis})
     def websocket_connect_VC(self):
         print("websocket_connect_VC:{} e:{}!!!!!!!!!!!!!!!!!!!!!".format(self.AI_client_VC_isconnect,self.AI_client_VC_debug))
@@ -346,6 +364,39 @@ class VCSessionIoMixin:
         except Exception:
             return False
 
+    def _vc_clean_ws_close_soft_reconnect_ok(self):
+        """仅 prompt notify 在途时软重连;对话 TTS 仍走原 drain+Close 链路。"""
+        try:
+            if getattr(self, "Close_flag", 0) == 1:
+                return False
+            if hasattr(self, "_vc_prompt_notify_in_flight"):
+                return self._vc_prompt_notify_in_flight()
+        except Exception:
+            pass
+        return False
+
+    def _vc_ws_soft_reconnect(self):
+        """对齐 play_tts_cb:deconnect+start,不 Close,避免掐断 prompt 播报。"""
+        print("[VC] ws soft reconnect (prompt notify, skip Close)")
+        try:
+            self.websocket_deconnect_VC()
+            self.AI_VC_start()
+        except Exception as e:
+            usys.print_exception(e)
+
+    def _vc_on_ws_link_closed(self, is_clean=True):
+        """WS 断链统一入口:prompt notify 在途优先软重连,对话链路保持原行为。"""
+        if self._vc_clean_ws_close_soft_reconnect_ok():
+            EventMesh.publish("publish_AI_btnInfo", {"func": self._vc_ws_soft_reconnect})
+            return
+        if is_clean:
+            EventMesh.publish("publish_AI_btnInfo", {"func": self.websocket_error, "data": None})
+        else:
+            EventMesh.publish(
+                "publish_AI_btnInfo",
+                {"func": self._vc_on_transport_error, "data": "VC连接断开了,请重试"},
+            )
+
     def _vc_wait_play_drain_before_close(self):
         """服务端 tts.done 后立刻 clean-close WS 时:TTS 音频已全部收到但本地 PCM 环形
         缓冲可能仍有数 100ms~数 s 未放完。此时若直接 Close()→play_pcm.close() 会丢弃尾音,
@@ -847,12 +898,11 @@ class VCSessionIoMixin:
                     # 服务器关闭连接
                     _ws_close_clean = self._vc_ws_close_is_clean()
                     print("[VC] ws server close clean={}".format(_ws_close_clean))
-                    _ws_err_str = None if _ws_close_clean else "VC连接断开了,请重试"
-                    if _ws_err_str is None:
-                        EventMesh.publish("publish_AI_btnInfo",{"func":self.websocket_error,"data":None})
-                    else:
-                        EventMesh.publish("publish_AI_btnInfo",{"func":self._vc_on_transport_error,"data":_ws_err_str})
-                    self.ud_error(["VC",self.VC_taskid])
+                    EventMesh.publish(
+                        "publish_AI_btnInfo",
+                        {"func": self._vc_on_ws_link_closed, "data": _ws_close_clean},
+                    )
+                    self.ud_error(["VC", self.VC_taskid])
                     break
                 elif recv_data == "":  # EOF:链路断开/对端关闭
                     try:
@@ -863,12 +913,11 @@ class VCSessionIoMixin:
                     print("[VC] ws EOF (link down) VC_mode={} sid={} clean={}".format(
                         getattr(self, "VC_mode", -1), sid, _ws_eof_clean
                     ))
-                    _ws_err_str = None if _ws_eof_clean else "VC连接断开了,请重试"
-                    if _ws_err_str is None:
-                        EventMesh.publish("publish_AI_btnInfo",{"func":self.websocket_error,"data":None})
-                    else:
-                        EventMesh.publish("publish_AI_btnInfo",{"func":self._vc_on_transport_error,"data":_ws_err_str})
-                    self.ud_error(["VC",self.VC_taskid])
+                    EventMesh.publish(
+                        "publish_AI_btnInfo",
+                        {"func": self._vc_on_ws_link_closed, "data": _ws_eof_clean},
+                    )
+                    self.ud_error(["VC", self.VC_taskid])
                     break
                 try:
                     self.websocket_error_count = 0
@@ -1019,6 +1068,12 @@ class VCSessionIoMixin:
                                     self._turn_has_asr_result = 1
                                     # 有效 ASR 后勿再执行空 ASR 提示音播完开麦
                                     self._vc_reopen_uplink_after_empty_hint = 0
+                                    if (
+                                        getattr(self, "VC_mode", -1) == 1
+                                        and getattr(self, "_ptt_await_server", 0) == 1
+                                        and hasattr(self, "_vc_ptt_clear_drop_tts_flags")
+                                    ):
+                                        self._vc_ptt_clear_drop_tts_flags()
                                     if hasattr(self, "_vc_note_asr_result_activity"):
                                         self._vc_note_asr_result_activity()
                             except Exception:
@@ -1043,59 +1098,20 @@ class VCSessionIoMixin:
                                     self.AI_ASR_str = getattr(self, "_last_asr_result_text", "") or ""
                             except Exception:
                                 pass
-                            # 本地 think 提示:仅在有有效 ASR 文本时播,避免空轮次连播「滴」
-                            # 本地 VAD endpoint 模式已在 _vc_local_vad_on_endpoint 播过,此处跳过 think.pcm
+                            # 长对话 think:有效 ASR → media 层统一调度;空 ASR → 没听清
                             try:
-                                if getattr(self, "_asr_completed_tone_done", 0) == 1:
-                                    pass
-                                elif not self._vc_effective_asr_text():
+                                if not self._vc_effective_asr_text():
                                     try:
                                         self._vc_handle_asr_empty("asr.completed")
                                     except Exception as e:
                                         usys.print_exception(e)
                                 else:
-                                    stream_on = False
-                                    try:
-                                        stream_on = EventMesh.publish("get_vc_tts_playback_active") == 1
-                                    except Exception:
-                                        stream_on = False
-                                    playing = getattr(self, "VC_Play_flag", 0) == 1
-                                    try:
-                                        thinking = getattr(self.fsm, "turn", VCTurnState.Idle) == VCTurnState.Thinking
-                                    except Exception:
-                                        thinking = False
-                                    vad_cont = getattr(self, "_vc_vad_had_active_after_silence", 0) == 1
-                                    # 本地 VAD endpoint 模式下 think.pcm 已由 local 路径播过,不必再播
-                                    _skip_think = False
-                                    try:
-                                        _skip_think = self._vc_local_vad_endpoint() and self._vc_is_long_dialogue_mode()
-                                    except Exception:
-                                        pass
-                                    if _skip_think:
-                                        try:
-                                            print("[VC][ASR] skip think tone (local endpoint already played)")
-                                        except Exception:
-                                            pass
-                                    elif (
-                                        (not stream_on)
-                                        and (not playing)
-                                        and (not thinking)
-                                        and (not vad_cont)
-                                        and getattr(self, "VC_record_state_flag", 0) < 2
+                                    if (
+                                        getattr(self, "VC_mode", -1) == 1
+                                        and hasattr(self, "_vc_ptt_clear_drop_tts_flags")
                                     ):
-                                        self._vc_local_play('U:/static/think.pcm', 1, 1, 650)
-                                        self._asr_completed_tone_done = 1
-                                    elif vad_cont:
-                                        try:
-                                            print("[VC][ASR] skip think tone (vad pause merged)")
-                                        except Exception:
-                                            pass
-                                    else:
-                                        try:
-                                            print("[VC][ASR] skip think tone stream={} play={} think={} vad={}".format(
-                                                int(stream_on), int(playing), int(thinking), int(vad_cont)))
-                                        except Exception:
-                                            pass
+                                        self._vc_ptt_clear_drop_tts_flags()
+                                    self._vc_on_asr_completed_think()
                             except Exception:
                                 pass
                             print("self.commands_mode:{}".format(self.commands_mode))
@@ -1215,23 +1231,38 @@ class VCSessionIoMixin:
                                 if self.VC_record_state_flag == 1:#llm返回数据还没停止,就先停止
                                     self.request_uplink_stop("llm.delta")
                         elif jsload_data["event"] == "tts.started" :#tts开始
-                            self._ptt_await_server = 0
-                            self._server_vad_silence = 1
-                            self._turn_has_tts_started = 1
-                            self._tts_pending = 0
-                            self._tts_pending_ms = 0
-                            self._uplink_mark_end("tts.started")
-                            payload = jsload_data.get("payload", {})
-                            did = payload.get("dialog_id", "") if isinstance(payload, dict) else ""
-                            if not did:
-                                did = getattr(self, "_cur_dialog_id", "") or ""
-                            self._last_tts_kind = self._vc_classify_llm_tts_kind(did)
-                            if self._last_tts_kind == "dialog":
-                                self._vc_expect_dialog_tts = 0
-                            self._pending_tts_kind = ""
-                            self._tts_completed_wall_ms = 0
+                            if not (
+                                hasattr(self, "_vc_ptt_drop_server_event")
+                                and self._vc_ptt_drop_server_event("tts.started", "recv")
+                            ):
+                                self._ptt_await_server = 0
+                                self._server_vad_silence = 1
+                                self._turn_has_tts_started = 1
+                                self._tts_pending = 0
+                                self._tts_pending_ms = 0
+                                self._uplink_mark_end("tts.started")
+                                payload = jsload_data.get("payload", {})
+                                did = payload.get("dialog_id", "") if isinstance(payload, dict) else ""
+                                if not did:
+                                    did = getattr(self, "_cur_dialog_id", "") or ""
+                                self._last_tts_kind = self._vc_classify_llm_tts_kind(did)
+                                if self._last_tts_kind == "dialog":
+                                    self._vc_expect_dialog_tts = 0
+                                if self._last_tts_kind == "prompt":
+                                    try:
+                                        self._ptt_stale_prompt_drop = 0
+                                        self._drop_tts_audio = 0
+                                    except Exception:
+                                        pass
+                                self._pending_tts_kind = ""
+                                self._tts_completed_wall_ms = 0
                         elif jsload_data["event"] == "tts.completed" :#tts结束
-                            if not self._vc_ignore_late_tts_completed_event():
+                            if (
+                                hasattr(self, "_vc_ptt_drop_server_event")
+                                and self._vc_ptt_drop_server_event("tts.completed", "recv")
+                            ):
+                                pass
+                            elif not self._vc_ignore_late_tts_completed_event():
                                 sid = getattr(self, "_cur_sid", "")
                                 did = getattr(self, "_cur_dialog_id", "")
                                 print("[TTS] completed in_len={} out_len={} q_empty={} play_pcm={} sid={} did={}".format(
@@ -1242,10 +1273,17 @@ class VCSessionIoMixin:
                                     sid,
                                     did,
                                 ))
-                                try:
-                                    self._tts_completed_wall_ms = utime.ticks_ms()
-                                except Exception:
-                                    self._tts_completed_wall_ms = 0
+                                # 仅对话 TTS 收尾参与 clean-close 判定;prompt notify 的迟到 completed 勿污染
+                                _k_done = (
+                                    getattr(self, "_pending_tts_kind", "")
+                                    or getattr(self, "_last_tts_kind", "")
+                                    or ""
+                                )
+                                if _k_done != "prompt":
+                                    try:
+                                        self._tts_completed_wall_ms = utime.ticks_ms()
+                                    except Exception:
+                                        self._tts_completed_wall_ms = 0
                                 if getattr(self, "VC_mode", 0) == 0:
                                     EventMesh.publish(
                                         "publish_AI_btnInfo",
index 4ef1e1a..e169233 100644 (file)
@@ -260,6 +260,8 @@ class VCSessionMediaMixin:
             r = str(reason or "")
             if r.startswith("key.restart"):
                 self._vc_key_restart_arm = 0
+                # 重开麦须新 audio.create;勿沿用上一轮 _ptt_audio_created 残留
+                self._ptt_audio_created = 0
         except Exception:
             pass
         try:
@@ -602,6 +604,19 @@ class VCSessionMediaMixin:
         except Exception:
             pass
 
+    def _vc_pcm_discard_soft_stopped_handle(self):
+        """打断软停后的 play_pcm 句柄可能「写入成功但无声」,下次播前硬关重建。"""
+        if getattr(self, "_vc_pcm_soft_stopped", 0) != 1:
+            return
+        try:
+            if self.play_pcm is not None:
+                self.play_pcm.stream_stop()
+                self.play_pcm.close()
+        except Exception:
+            pass
+        self.play_pcm = None
+        self._vc_pcm_soft_stopped = 0
+
     def _vc_soft_stop_tts_pcm(self, reason=""):
         """停 TTS 流、清队列,保留 play_pcm handle(供本地 PCM 短音复用)。"""
         try:
@@ -613,6 +628,13 @@ class VCSessionMediaMixin:
                 self.play_pcm.stream_stop()
         except Exception:
             pass
+        # 仅打断/停播类软停需硬重建;播完收尾、local 短音打断 TTS 仍复用给 think/start
+        try:
+            r = str(reason or "")
+            if r not in ("play_soft_end", "local_pcm"):
+                self._vc_pcm_soft_stopped = 1
+        except Exception:
+            pass
         try:
             if getattr(self, "AI_audio_queue", None) is not None:
                 if self.AI_audio_queue.empty() != True:
@@ -637,6 +659,7 @@ class VCSessionMediaMixin:
         last_err = None
         for i in range(3):
             try:
+                self._vc_pcm_discard_soft_stopped_handle()
                 reuse = getattr(self, "play_pcm", None) is not None
                 if self.play_pcm is None:
                     if i > 0:
@@ -679,7 +702,7 @@ class VCSessionMediaMixin:
             utime.sleep_ms(10)
 
     def _vc_local_play_pcm(self, path, hold_ms=650):
-        """本地 PCM 短音:走 play_pcm 写流;打断 TTS 时 soft-stop,不 close handle。"""
+        """本地 PCM 短音:走 play_pcm 写流;打断 TTS 时 soft-stop,不 close handle。成功返回 True。"""
         try:
             from vc_media_arb import MediaArbiter
             if MediaArbiter.llm_active(self):
@@ -699,13 +722,21 @@ class VCSessionMediaMixin:
             self._vc_local_play_until_ms = utime.ticks_add(utime.ticks_ms(), hold)
         except Exception:
             pass
+        total = 0
+        real_path = path
         try:
             self._vc_set_playback_volume(reason="local_pcm")
             fd, real_path = self._vc_open_static_file(path)
             try:
-                self._vc_play_pcm_stream_begin(after_file=0)
+                wr_start = self._vc_play_pcm_stream_begin(after_file=0)
+                if wr_start is not None:
+                    try:
+                        if int(wr_start) < 0:
+                            print("[VC] local_pcm stream_write_start fail ret={}".format(wr_start))
+                            return False
+                    except Exception:
+                        pass
                 chunk = 3200
-                total = 0
                 while True:
                     buf = fd.read(chunk)
                     if not buf:
@@ -713,16 +744,29 @@ class VCSessionMediaMixin:
                     if not isinstance(buf, bytearray):
                         buf = bytearray(buf)
                     n = self.play_pcm.stream_write(buf, len(buf))
+                    if n is not None and n < 0:
+                        print("[VC] local_pcm stream_write fail n={}".format(n))
+                        total = 0
+                        break
                     total += n if n else 0
                 print("[VC] local_pcm wrote {} bytes path={}".format(total, real_path))
+                if total > 0:
+                    try:
+                        sr = int(getattr(self, "VC_play_samplerate", 16000))
+                        dur_ms = (total * 1000) // (sr * 2) + 50
+                        if dur_ms > 500:
+                            dur_ms = 500
+                        utime.sleep_ms(dur_ms)
+                    except Exception:
+                        pass
+                    return True
                 try:
-                    sr = int(getattr(self, "VC_play_samplerate", 16000))
-                    dur_ms = (total * 1000) // (sr * 2) + 50
-                    if dur_ms > 500:
-                        dur_ms = 500
-                    utime.sleep_ms(dur_ms)
+                    if self.play_pcm is not None:
+                        self.play_pcm.close()
                 except Exception:
                     pass
+                self.play_pcm = None
+                return False
             finally:
                 fd.close()
         except OSError as e:
@@ -734,6 +778,7 @@ class VCSessionMediaMixin:
             mp3_path = str(path)[:-4] + ".mp3"
             print("[VC] local_pcm open fail err={} fallback mp3={}".format(e, mp3_path))
             self._vc_local_play_mp3_file(mp3_path, hold_ms=hold_ms)
+            return True
         except Exception as e:
             try:
                 self._vc_local_play_active = 0
@@ -741,13 +786,88 @@ class VCSessionMediaMixin:
             except Exception:
                 pass
             usys.print_exception(e)
+            return False
+
+    def _vc_think_tone_can_play_now(self):
+        """长对话 think 提示:TTS/思考态/merge 续说窗内不播。"""
+        if getattr(self, "_vc_vad_had_active_after_silence", 0) == 1:
+            return False
+        try:
+            stream_on = EventMesh.publish("get_vc_tts_playback_active") == 1
+        except Exception:
+            stream_on = False
+        if stream_on or getattr(self, "VC_Play_flag", 0) == 1:
+            return False
+        try:
+            thinking = getattr(self.fsm, "turn", VCTurnState.Idle) == VCTurnState.Thinking
+        except Exception:
+            thinking = False
+        return not thinking
+
+    def _vc_arm_think_tone_pending(self):
+        """长对话句末挂 think 待播:仅标记,由 record_poll 在 gate 排空后执行。"""
+        if not self._vc_is_long_dialogue_mode():
+            return
+        if getattr(self, "_asr_completed_tone_done", 0) == 0:
+            self._think_tone_pending = 1
+
+    def _vc_on_asr_completed_think(self):
+        """asr.completed 后 think 调度(io 层唯一入口)。
+        本地 VAD:句末 record_poll 主播,此处仅 pending 未清时补播。
+        云端 VAD:此处直接播;忙则挂 pending。"""
+        if getattr(self, "_asr_completed_tone_done", 0) == 1:
+            return
+        if not self._vc_is_long_dialogue_mode():
+            return
+        if not self._vc_effective_asr_text():
+            return
+        if getattr(self, "_vc_vad_had_active_after_silence", 0) == 1:
+            return
+        if self._vc_local_vad_endpoint():
+            if getattr(self, "_think_tone_pending", 0) == 1:
+                self._vc_try_play_think_tone(via="asr.completed/local")
+            return
+        if not self._vc_try_play_think_tone(via="asr.completed"):
+            if getattr(self, "_asr_completed_tone_done", 0) == 0:
+                self._think_tone_pending = 1
+
+    def _vc_try_play_think_tone(self, via=""):
+        """长对话 think 唯一播放入口;播放前占坑 tone_done 防 record_poll/asr.completed 双播。"""
+        if getattr(self, "_asr_completed_tone_done", 0) == 1:
+            self._think_tone_pending = 0
+            return True
+        if not self._vc_is_long_dialogue_mode():
+            return False
+        if not self._vc_think_tone_can_play_now():
+            return False
+        # 播放前占坑:record_poll 与 asr.completed 并发时防双播(local_pcm 内有 sleep)
+        self._asr_completed_tone_done = 1
+        self._think_tone_pending = 0
+        ok = False
+        try:
+            ok = bool(self._vc_local_play("U:/static/think.pcm", 1, 1, 650))
+        except Exception:
+            ok = False
+        if ok:
+            try:
+                print("[VC][think] play via={}".format(via or "-"))
+            except Exception:
+                pass
+            return True
+        self._asr_completed_tone_done = 0
+        self._think_tone_pending = 1
+        try:
+            print("[VC][think] play fail via={}".format(via or "-"))
+        except Exception:
+            pass
+        return False
 
     def _vc_local_play(self, path, play_mode=1, loop=1, hold_ms=650):
         """本地短音:.pcm 走 play_pcm 复用;其他仍 aud.play(montage/开机铃等不变)。"""
         if self._vc_is_local_pcm_path(path):
-            self._vc_local_play_pcm(path, hold_ms=hold_ms)
-            return
+            return self._vc_local_play_pcm(path, hold_ms=hold_ms)
         self._vc_local_play_mp3_file(path, play_mode=play_mode, loop=loop, hold_ms=hold_ms)
+        return True
     def _vc_merge_asr_stream_text(self, new_text):
         """流式 asr.result 常为整句覆盖;同轮连续多句时拼接,避免 completed 只剩最后一句。"""
         new_t = (new_text or "").strip()
@@ -835,6 +955,7 @@ class VCSessionMediaMixin:
         if not self._vc_local_vad_endpoint():
             return
         if getattr(self, "_ptt_audio_created", 0) == 1:
+            print("[VC][proto] audio.create skip (flag=1, expect new round cleared)")
             return
         try:
             self.AI_client_VC_send_speech()
@@ -886,13 +1007,7 @@ class VCSessionMediaMixin:
         self._server_vad_silence = 1
         self._uplink_mark_end("local.vad.end")
         self._vc_local_vad_send_audio_completed(defer_stop=False)
-        # 标记 think 待播:等 Speech_End 之后录音线程再播,避免阻塞尾音排空
-        try:
-            if self._vc_is_long_dialogue_mode() and getattr(self, "_asr_completed_tone_done", 0) == 0:
-                self._asr_completed_tone_done = 1
-                self._think_tone_pending = 1
-        except Exception:
-            pass
+        self._vc_arm_think_tone_pending()
 
     def _vc_endpoint_hangover_ms(self):
         """本地 VAD 句末后追加采集的尾音时长(ms);0=不延迟立即收尾。"""
@@ -1489,6 +1604,7 @@ class VCSessionMediaMixin:
         try:
             if int(getattr(self, "VC_mode", 0)) == 1:
                 self._ptt_record_open_ms = utime.ticks_ms()
+                self.AI_key_long_press_flag = 1
         except Exception:
             pass
         print("[VC] Speech_Start_now record_state={}".format(self.VC_record_state_flag))
@@ -1501,7 +1617,8 @@ class VCSessionMediaMixin:
                 return
             
             if self.VC_record_state_flag  == 0:
-                # 新一轮开始录音:允许上行(上一轮可能已置 silence 闸门)
+                # 新一轮录音:清协议轮次标记,确保 local_vad/PTT 会发 audio.create
+                self._ptt_audio_created = 0
                 self._vc_drop_reset()
                 self._server_vad_silence = 0
                 try:
@@ -1682,12 +1799,16 @@ class VCSessionMediaMixin:
             if getattr(self, "VC_mode", -1) == 1:
                 self._ptt_led_lock_listening = 0
                 self._ptt_interrupt_active = 0
-                if hasattr(self, "_ptt_release_has_speech") and self._ptt_release_has_speech():
+                if hasattr(self, "_ptt_release_should_await_server") and self._ptt_release_should_await_server():
                     self._ptt_await_server = 1
                     try:
                         self._ptt_await_since_ms = utime.ticks_ms()
                     except Exception:
                         self._ptt_await_since_ms = 0
+                    try:
+                        self._vc_ptt_clear_late_tts_suppress("await_server")
+                    except Exception:
+                        pass
                     if hasattr(self, "_vc_ptt_clear_drop_tts_flags"):
                         self._vc_ptt_clear_drop_tts_flags()
                     self._vc_publish_led("thinking", "VC_Speech_End/ptt")
@@ -1722,6 +1843,16 @@ class VCSessionMediaMixin:
                         or getattr(self, "_vc_ld_awaiting_reply", 0) == 1
                     ) and self._vc_effective_asr_text():
                         self._vc_publish_led("thinking", "VC_Speech_End/force_commit")
+                    elif (
+                        getattr(self, "_vc_turn_had_speech", 0)
+                        or getattr(self, "_turn_has_vad_silence", 0)
+                        or getattr(self, "_turn_has_asr_result", 0)
+                    ):
+                        try:
+                            self._vc_ld_awaiting_reply = 1
+                        except Exception:
+                            pass
+                        self._vc_publish_led("thinking", "VC_Speech_End/vad_submit")
                     else:
                         self._vc_publish_led("idle", "VC_Speech_End/long_wait")
                 else:
@@ -2042,13 +2173,10 @@ class VCSessionMediaMixin:
                     usys.print_exception(e)
                     #break
             self.VC_record_thread_lock = 0
-            # 尾音 gate buffer 排空后 think 提示音才播,避免阻塞排空被 aud.stopPlayStream 冲掉
+            # 尾音 gate 排空后再播 think;失败保留 pending,下轮 record_poll 重试
             try:
                 if getattr(self, "_think_tone_pending", 0) == 1:
-                    self._think_tone_pending = 0
-                    stream_on = EventMesh.publish("get_vc_tts_playback_active") == 1
-                    if (not stream_on) and getattr(self, "VC_Play_flag", 0) == 0:
-                        self._vc_local_play('U:/static/think.pcm', 1, 1, 650)
+                    self._vc_try_play_think_tone(via="record_poll")
             except Exception:
                 pass
             if self.record_data_save_flag == 1:
@@ -2312,6 +2440,7 @@ class VCSessionMediaMixin:
                     pass
                 if self.VC_play_TYPE == VC_play_TYPE_PCM:
                     self._vc_wait_local_pcm_drain()
+                    self._vc_pcm_discard_soft_stopped_handle()
                     if self.play_pcm == None:
                         # 刚停采集时延后打开播音 PCM,且失败时重试,降低「pcm open write only fail」
                         last_err = None
@@ -2596,6 +2725,41 @@ class VCSessionMediaMixin:
                 (in_len - out_len) <= slack
             ) or (out_len + pcm_pending_pre >= in_len - slack)
             if not played_ok:
+                try:
+                    last_out = getattr(self, "_tts_play_end_last_out", -1)
+                    stuck_ms = getattr(self, "_tts_play_end_out_stuck_ms", 0)
+                    if out_len > 0 and out_len == last_out:
+                        if not stuck_ms:
+                            self._tts_play_end_out_stuck_ms = now
+                        elif utime.ticks_diff(now, stuck_ms) >= 3000:
+                            print(
+                                "[TTS] play_end_force out_stuck in={} out={}".format(
+                                    in_len, out_len))
+                            self._tts_play_end_out_stuck_ms = 0
+                            self._tts_play_end_last_out = 0
+                            self._vc_fire_local_play_end("out_stuck")
+                            return True
+                    else:
+                        self._tts_play_end_out_stuck_ms = 0
+                    self._tts_play_end_last_out = out_len
+                except Exception:
+                    pass
+                try:
+                    if (
+                        getattr(self, "VC_Play_flag", 0) == 0
+                        and out_len > 0
+                        and since_done >= 3000
+                        and (in_len - out_len) > slack
+                    ):
+                        print(
+                            "[TTS] play_end_force interrupted in={} out={}".format(
+                                in_len, out_len))
+                        self._tts_play_end_out_stuck_ms = 0
+                        self._tts_play_end_last_out = 0
+                        self._vc_fire_local_play_end("interrupted")
+                        return True
+                except Exception:
+                    pass
                 try:
                     if not getattr(self, "_tts_play_check_log_ms", 0) or utime.ticks_diff(
                         utime.ticks_ms(), self._tts_play_check_log_ms
@@ -2732,16 +2896,27 @@ class VCSessionMediaMixin:
         EventMesh.publish("publish_AI_btnInfo",{"func":self._uplink_request_stop, "data":"audio.completed"})
     def AI_client_VC_synthesis(self):
         # 幂等保护:在上一条 synthesis 还未等到 tts.started 前,不重复发(防止多兜底/多入口重复触发)
+        _syn_kind = ""
         try:
-            if self._tts_pending == 1:
-                return
+            _syn_kind = getattr(self, "_pending_tts_kind", "") or getattr(self, "_last_tts_kind", "") or ""
         except Exception:
             pass
-        _syn_text = self.AI_TTS_str or ""
         try:
-            _syn_kind = getattr(self, "_pending_tts_kind", "") or getattr(self, "_last_tts_kind", "") or ""
+            if self._tts_pending == 1:
+                # prompt 须先 _vc_cancel_prompt_notify_in_flight 清 pending 再发
+                print("[VC][syn] skip dup pending kind={}".format(_syn_kind or "-"))
+                return
         except Exception:
-            _syn_kind = ""
+            pass
+        _syn_text = str(self.AI_TTS_str or "").strip()
+        if not _syn_text:
+            print("[VC][syn] skip empty synthesis kind={}".format(_syn_kind or "-"))
+            try:
+                self._tts_pending = 0
+                self._tts_pending_ms = 0
+            except Exception:
+                pass
+            return
         try:
             vc_proto_log_synthesis(_syn_text, _syn_kind)
         except Exception: