From: TimekeeperPL <1624952103@qq.com> Date: Mon, 1 Jun 2026 10:04:27 +0000 (+0800) Subject: 1.优化单对话模式 长按按键打断TTS后状态异常无法继续对话的情况。2.优化单对话模式长按键不说话松开以后状态异常无法对话的情况(补) X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=960534764aa326d3319803cdcf87b956aca83721;p=mirrors%2FASR1603_G5.git 1.优化单对话模式 长按按键打断TTS后状态异常无法继续对话的情况。2.优化单对话模式长按键不说话松开以后状态异常无法对话的情况(补) --- diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session.py index 366edad5..943fa33c 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session.py @@ -54,6 +54,7 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract): self._vc_cancel_deadline_ms = 0 self._ptt_force_record_on_started = 0 self._ptt_await_server = 0 + self._ptt_await_since_ms = 0 self._ptt_audio_created = 0 except Exception: pass @@ -532,6 +533,16 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract): def _vc_ignore_late_tts_completed_event(self): """打断后已停播/开麦:迟到的 tts.completed 不参与 await_played / play_end。""" try: + if self._vc_is_ptt_mode() and not self._vc_tts_playback_active(): + 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, "is_ruppt_tts", 0) + or getattr(self, "_drop_tts_audio", 0) + or getattr(self, "AI_key_long_press_flag", 0) + ) return ( self._vc_is_long_dialogue_mode() and not self._vc_tts_playback_active() @@ -545,6 +556,13 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract): except Exception: return False + def _ptt_release_has_speech(self): + """PTT 松手:仅认本轮 AI_ASR_str,勿用 _last_asr_result_text(上轮残留会误进 thinking)。""" + try: + return bool((getattr(self, "AI_ASR_str", "") or "").strip()) + except Exception: + return False + def _long_dialogue_should_drop_inbound_tts(self): """长对话打断窗口:丢弃迟到 TTS 帧 / 禁止起播。""" if not self._vc_is_long_dialogue_mode(): @@ -1189,9 +1207,10 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract): usys.print_exception(e) def _vc_handle_asr_empty_ptt(self, hint, reason="asr.completed"): - """单对话:idle + Notify(不断线重连的轻量路径仍走 play_tts)。""" + """单对话:松手无声→idle+cancel;服务端 asr.completed 空文本→播没听清。""" try: self._ptt_await_server = 0 + self._ptt_await_since_ms = 0 self._ptt_audio_created = 0 self._ptt_defer_speech_until_asr = 0 self._ptt_record_open_ms = 0 @@ -1209,9 +1228,14 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract): if getattr(self, "AI_client_VC_isconnect", 0) == 1 and getattr( self, "_vc_session_started", 0 ) == 1: - self._vc_send_protocol_cancel("asr.empty") + tag = "ptt_silent_release" if reason != "asr.completed" else "asr.empty" + self._vc_send_protocol_cancel(tag) except Exception: pass + if reason != "asr.completed": + print("[PTT] silent release -> idle (skip empty_hint)") + self._vc_publish_led("idle", reason) + return try: EventMesh.publish("play_tts", [hint, 0, "prompt"]) except Exception: @@ -2365,6 +2389,7 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract): self._ptt_audio_created = 0 # PTT:松手等服务器期间保持 thinking 勿回蓝闪聆听 self._ptt_await_server = 0 + self._ptt_await_since_ms = 0 # 方案甲 btnInfo 串行:打断时先 cancel,收到 canceled(或超时)后再 audio.create self._vc_serial_canceling = 0 self._ptt_pending_arm = 0 @@ -3407,6 +3432,24 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract): except Exception: pass + # 1b) PTT 松手等 ASR/LLM:超时回 idle(防无声/空轮次一直蓝绿闪) + try: + if getattr(self, "VC_mode", -1) == 1 and getattr(self, "_ptt_await_server", 0): + since = getattr(self, "_ptt_await_since_ms", 0) + if since and utime.ticks_diff(now_ms, since) > cfg_int( + "PTT_AWAIT_SERVER_TIMEOUT_MS", 6000 + ): + self._ptt_await_server = 0 + self._ptt_await_since_ms = 0 + try: + self._vc_send_protocol_cancel("ptt_await_timeout") + self.fsm.reset_rx_phases() + except Exception: + pass + self._vc_publish_led("idle", "ptt_await_timeout") + except Exception: + pass + # 2) thinking 超时:只在「llm.completed 已收到但 tts.started 长时间未到」时才重启会话 # 注意:不能以 llm.created 的时间戳作为超时基准,否则会在 LLM 正常推理期间误判超时(notts 场景)。 try: diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_io.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_io.py index d24838f1..6ab472f0 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_io.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_io.py @@ -917,25 +917,26 @@ class VCSessionIoMixin: self._pending_tts_kind = "" self._tts_completed_wall_ms = 0 elif jsload_data["event"] == "tts.completed" :#tts结束 - 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( - getattr(self, "tts_in_data_len", 0), - getattr(self, "tts_out_data_len", 0), - 1 if self.AI_audio_queue.empty() else 0, - 1 if self.play_pcm != None else 0, - sid, - did, - )) - 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}, - ) + if 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( + getattr(self, "tts_in_data_len", 0), + getattr(self, "tts_out_data_len", 0), + 1 if self.AI_audio_queue.empty() else 0, + 1 if self.play_pcm != None else 0, + sid, + did, + )) + 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}, + ) # 播完上报完全由 FSM await_played + play_end 驱动 elif jsload_data["event"] == "canceled" :#打断 diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_media.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_media.py index ac66dd1b..534d8409 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_media.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_media.py @@ -1184,10 +1184,19 @@ class VCSessionMediaMixin: if getattr(self, "VC_mode", -1) == 1: self._ptt_led_lock_listening = 0 self._ptt_interrupt_active = 0 - self._ptt_await_server = 1 - 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") + if hasattr(self, "_ptt_release_has_speech") and self._ptt_release_has_speech(): + self._ptt_await_server = 1 + try: + self._ptt_await_since_ms = utime.ticks_ms() + except Exception: + self._ptt_await_since_ms = 0 + 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") + else: + self._ptt_await_server = 0 + self._ptt_await_since_ms = 0 + self._vc_handle_asr_empty("ptt_release/silent") else: self._ptt_await_server = 0 if (