修复单对话模式 状态灯异常问题
authorTimekeeperPL <1624952103@qq.com>
Wed, 24 Jun 2026 08:07:18 +0000 (16:07 +0800)
committerTimekeeperPL <1624952103@qq.com>
Wed, 24 Jun 2026 08:07:18 +0000 (16:07 +0800)
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 0d99fc7..3bde72a 100644 (file)
@@ -2126,6 +2126,10 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
         except Exception:
             pass
         print("[PTT] release no record -> idle (skip too_short)")
+        try:
+            self._ptt_abort_press_without_record()
+        except Exception:
+            pass
         try:
             self._vc_publish_led("idle", "ptt_no_record")
         except Exception:
@@ -2242,6 +2246,18 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
             self.is_ruppt_tts = 0
         except Exception:
             pass
+
+    def _ptt_abort_press_without_record(self):
+        """PTT 按下未成录:撤 pending 开录与聆听灯锁(idle 短按 / 松手未录上)。"""
+        if not self._vc_is_ptt_mode():
+            return
+        try:
+            self._ptt_abort_interrupt_arm()
+            self._ptt_pending_arm = 0
+            self._vc_serial_canceling = 0
+            self._vc_cancel_deadline_ms = 0
+        except Exception:
+            pass
     def _ptt_on_record_hardware_started(self):
         """真开录后:允许新 TTS;聆听灯锁保持至松手 VC_Speech_End。"""
         try:
@@ -2528,6 +2544,7 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
             self._tts_pending = 0
             self._tts_pending_ms = 0
             self._tts_completed_wall_ms = 0
+            self._tts_play_end_due_ms = 0
             try:
                 self.fsm.last_tts_completed_ms = 0
             except Exception:
@@ -3320,6 +3337,7 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
         self.tts_out_data_len = 0
         self._tts_first_write_ms = 0
         self._tts_completed_wall_ms = 0
+        self._tts_play_end_due_ms = 0
         self._tts_play_check_log_ms = 0
         self._need_audio_played_ack = 0#tts.completed 后需在本地播报结束后上报 audio.played;勿用 tts_in/out:tts.completed 会再调 VC_Play_Start 把二者清零
         self.VC_satrt_flag = 0
@@ -4078,6 +4096,14 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
                 self._vc_cancel_prompt_notify_in_flight(reason or "notify_replace")
             except Exception:
                 pass
+            if (
+                self._vc_is_ptt_mode()
+                and getattr(self, "VC_record_state_flag", 0) == 0
+            ):
+                try:
+                    self._ptt_abort_press_without_record()
+                except Exception:
+                    pass
             try:
                 self._pending_tts_kind = TTS_KIND_PROMPT
                 self._last_tts_kind = TTS_KIND_PROMPT
@@ -4111,6 +4137,11 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract):
     def _ptt_play_idle_hint(self):
         """PTT idle 短按:notify 话术提醒(对齐 k8 PTT_HINT,非 KEY_PRESS 本地音)。"""
         try:
+            self._ptt_abort_press_without_record()
+            try:
+                self._vc_publish_led("idle", "ptt_idle_hint/pre")
+            except Exception:
+                pass
             tts_str = (
                 cfg_attr("PTT_HINT", None)
                 or cfg_attr("KWS_PTT_HINT", None)
index 668c3e2..c0b4fec 100644 (file)
@@ -218,6 +218,11 @@ class VCSessionIoMixin:
             usys.print_exception(e)
         if ev == "canceled" and self._vc_is_ptt_mode():
             self._vc_on_ptt_cancel_settled(via="canceled")
+        if ev == "tts.completed" and getattr(self.fsm, "await_played", False):
+            try:
+                self._vc_try_play_end_tick()
+            except Exception:
+                pass
 
     def _vc_dispatch_server_event(self, ev, jsload_data=None):
         """recv 线程:仅入编排队列,不在此修改 FSM。tts.started 走高优队列减小播放延迟。"""
@@ -849,7 +854,7 @@ class VCSessionIoMixin:
                                 usys.print_exception(e)
 
                     utime.sleep_ms(1)
-        self.AI_VC_send_data_queue_thread_lock = 0              
+        self.AI_VC_send_data_queue_thread_lock = 0
     def AI_client_VC_recv_thread_close(self):
         if self.AI_client_VC_recv_id != 0:
             count =500
@@ -1256,6 +1261,7 @@ class VCSessionIoMixin:
                                         pass
                                 self._pending_tts_kind = ""
                                 self._tts_completed_wall_ms = 0
+                                self._tts_play_end_due_ms = 0
                         elif jsload_data["event"] == "tts.completed" :#tts结束
                             if (
                                 hasattr(self, "_vc_ptt_drop_server_event")
@@ -1273,22 +1279,25 @@ class VCSessionIoMixin:
                                     sid,
                                     did,
                                 ))
-                                # 仅对话 TTS 收尾参与 clean-close 判定;prompt notify 的迟到 completed 勿污染
+                                # play_end 用 _tts_play_end_due_ms;clean-close 仅对话 TTS 写 wall_ms
                                 _k_done = (
                                     getattr(self, "_pending_tts_kind", "")
                                     or getattr(self, "_last_tts_kind", "")
                                     or ""
                                 )
+                                try:
+                                    self._tts_play_end_due_ms = utime.ticks_ms()
+                                except Exception:
+                                    self._tts_play_end_due_ms = 0
                                 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",
-                                        {"func": self._vc_try_play_end_tick},
-                                    )
+                                EventMesh.publish(
+                                    "publish_AI_btnInfo",
+                                    {"func": self._vc_try_play_end_tick},
+                                )
                             # 播完上报完全由 FSM await_played + play_end 驱动
 
                         elif jsload_data["event"] == "canceled" :#打断
index e169233..dc11cd2 100644 (file)
@@ -419,6 +419,11 @@ class VCSessionMediaMixin:
 
     def _vc_orchestrator_play_end_cb(self, tag=""):
         """btn 编排线程:TTS 播完统一收尾。"""
+        try:
+            self._tts_play_end_due_ms = 0
+            self._tts_completed_wall_ms = 0
+        except Exception:
+            pass
         try:
             if tag:
                 print("[TTS] play_end_{}".format(tag))
@@ -2509,14 +2514,20 @@ class VCSessionMediaMixin:
 
     def _vc_play_end_after_stop(self, tag="VC_Play_End"):
         """TTS/下行停播后统一恢复灯与 notify 队列(软/硬关共用)。"""
+        try:
+            if getattr(self, "VC_mode", -1) == 1 and getattr(self, "VC_record_state_flag", 0) == 0:
+                self._vc_play_end_suppress_idle_led = 0
+                self._ptt_led_lock_listening = 0
+        except Exception:
+            pass
         try:
             if self._ptt_should_force_idle_led():
                 self._vc_publish_led("idle", tag + "/ptt_stop")
             elif getattr(self, "_vc_play_end_suppress_idle_led", 0) or self._vc_should_hold_listening_led():
                 if self._vc_should_hold_listening_led():
                     self._vc_publish_listening_for_mode(tag + "/listen_hold")
-                elif self._vc_led_state_debug_enabled():
-                    print("[LED] {} skip led (suppress)".format(tag))
+                else:
+                    self._vc_led_sync_from_fsm()
             elif getattr(self, "VC_record_state_flag", 0) != 0:
                 if getattr(self, "VC_mode", 0) == 0:
                     self._vc_publish_listening_for_mode(tag + "/recording")
@@ -2667,6 +2678,7 @@ class VCSessionMediaMixin:
         self._tts_first_write_ms = 0
         try:
             self._tts_completed_wall_ms = 0
+            self._tts_play_end_due_ms = 0
         except Exception:
             pass
 
@@ -2681,8 +2693,11 @@ class VCSessionMediaMixin:
                 q_empty = self.AI_audio_queue.empty()
             except Exception:
                 q_empty = True
-            tts_done_ms = getattr(self, "_tts_completed_wall_ms", 0) or getattr(
-                self.fsm, "last_tts_completed_ms", 0)
+            tts_done_ms = (
+                getattr(self, "_tts_play_end_due_ms", 0)
+                or getattr(self, "_tts_completed_wall_ms", 0)
+                or getattr(self.fsm, "last_tts_completed_ms", 0)
+            )
             if not (q_empty and tts_done_ms):
                 return False
             now = utime.ticks_ms()
@@ -2809,6 +2824,15 @@ class VCSessionMediaMixin:
             # 与旧 ai_VC LocalRespondingEnded 一致:stream 空且环形缓冲无待播数据
             pcm_drained = is_pcm_empty and pcm_pending == 0
             ready = pcm_drained and tail_ok
+            # 尾包差 1~2 帧且队列已空:尽快收尾,避免 _led_override 卡在 playing
+            if not ready and q_empty and played_ok and since_done >= 400:
+                try:
+                    gap = in_len - out_len
+                    if gap <= max(4096, slack) and pcm_pending <= max(4096, slack):
+                        if is_pcm_empty or since_done >= 1200:
+                            ready = True
+                except Exception:
+                    pass
             # 服务端 completed 后长时间仍不满足:队列已空则强制收尾,避免绿灯常亮不开麦
             if not ready and q_empty and tts_done_ms:
                 try: