self._long_dialogue_publish_listening("server.started")
except Exception:
pass
+ try:
+ if getattr(self, "_long_dialogue_key_arm", 0) == 1:
+ self._vc_pcm_prewarm_session_handle("server.started/key")
+ except Exception:
+ pass
try:
self._vc_on_server_record_uplink_ready("server.started")
except Exception:
self._ptt_force_record_on_started = 0
except Exception:
pass
+ try:
+ if _ptt_rec:
+ self._vc_pcm_prewarm_session_handle("server.started/ptt")
+ except Exception:
+ pass
try:
self.AI_client_VC_send_speech()
except Exception:
EventMesh.publish("set_led_state", {"alert": "rb_flash_2"})
except Exception:
pass
+ def _vc_clear_key_restart_round_state(self):
+ """录音中短按重开:清 merge/VAD/ASR 残留,作废未说完的一轮。"""
+ try:
+ self.AI_ASR_str = ""
+ self.AI_ASR_str_tmp = ""
+ self.AI_ASR_flag = 0
+ self._vc_pending_asr_completed_stop = 0
+ self._vc_defer_vad_uplink_stop = 0
+ self._vc_endpoint_hangover_until = 0
+ self._server_vad_silence = 0
+ self._vc_asr_continue_merge = 0
+ self.fsm.await_played = False
+ except Exception:
+ pass
+
def _vc_restart_record_same_dialog(self):
- """长对话 recording+短按:停录后立即重开(旧 sid,对齐设计稿)。"""
+ """长对话 recording+短按:停录 → cancel(旧 sid) → 滴 → 再开麦。"""
if not self._vc_is_long_dialogue_mode():
return False
try:
self._vc_reset_long_idle_timer("key.restart")
self._vc_long_dialogue_key_arm_session()
self._long_dialogue_publish_listening("key.restart")
+ self._vc_clear_key_restart_round_state()
self._vc_clear_stale_record_state("key.restart/pre")
self.request_uplink_stop("key.restart/stop")
self._vc_clear_stale_record_state("key.restart/post")
+ self._vc_key_restart_arm = 1
+ try:
+ if getattr(self, "AI_client_VC_isconnect", 0) == 1:
+ self.AI_client_VC_send(
+ ujson.dumps({"event": "cancel", "payload": {}}))
+ print("[KEY] long_dialogue restart -> cancel (keep sid)")
+ except Exception:
+ pass
+ try:
+ self.fsm.reset_rx_phases()
+ if getattr(self.fsm, "session", None) == VCSessionState.Started:
+ self.fsm.turn = VCTurnState.Listening
+ except Exception:
+ pass
self.request_uplink_start("key.restart/start")
return True
except Exception as e:
except Exception:
pass
try:
- if getattr(self, "VC_Play_flag", 0) == 1 or getattr(self, "play_pcm", None) is not None:
- self.VC_Play_End()
+ self._vc_downlink_stop_playback("local_priority_mute")
except Exception:
pass
def _vc_turn_current(self):
except Exception:
pass
try:
- if getattr(self, "VC_Play_flag", 0) == 1 or getattr(self, "play_pcm", None) is not None:
+ if getattr(self, "VC_Play_flag", 0) == 1:
+ self._vc_soft_stop_tts_pcm("ptt_deferred_cleanup")
+ elif (
+ getattr(self, "play_pcm", None) is not None
+ and self._vc_pcm_session_keep_open()
+ ):
+ try:
+ self.play_pcm.stream_stop()
+ except Exception:
+ pass
+ self.VC_Play_flag = 0
+ elif getattr(self, "VC_Play_flag", 0) == 1 or getattr(self, "play_pcm", None) is not None:
self.VC_Play_End()
except Exception:
pass
pass
if in_session:
try:
- if getattr(self, "VC_Play_flag", 0) == 1 or getattr(self, "play_pcm", None) is not None:
- self.VC_Play_End()
+ if getattr(self, "VC_Play_flag", 0) == 1:
+ self._vc_soft_stop_tts_pcm("ptt_begin")
+ elif getattr(self, "play_pcm", None) is not None:
+ try:
+ self.play_pcm.stream_stop()
+ except Exception:
+ pass
+ self.VC_Play_flag = 0
except Exception:
pass
try:
self._ptt_idle_latch = 0
self._ptt_short_press_stop = 0
self._long_dialogue_key_arm = 0
+ self._vc_key_restart_arm = 0
# AI 键短/长按开录:置位后等 server.started / asr.started(或会话已 started)再播 start.mp3
self._vc_pending_record_start_tone = 0
# PTT:已 started 时等 asr.started 滴后再 VC_Speech_Start
self._vc_pending_record_start_tone = 0
self._vc_pending_key_press_tone = 0
self._ptt_defer_speech_until_asr = 0
+ self._vc_key_restart_arm = 0
except Exception:
pass
try:
r = str(reason or "")
if r.startswith("key.press") or r.startswith("BT_AI_key_press"):
return True
+ if r.startswith("key.restart"):
+ return True
if r.startswith("ptt_begin") or r == "asr.started/defer":
return True
if r == "canceled" and (
try:
self._vc_defer_listening_led = 0
self._vc_skip_local_play_stop_record = 0
+ r = str(reason or "")
+ if r.startswith("key.restart"):
+ self._vc_key_restart_arm = 0
except Exception:
pass
try:
except Exception:
pass
try:
- if self._vc_pcm_session_keep_open() and self._vc_is_long_dialogue_mode():
+ if self._vc_pcm_session_keep_open():
self.VC_Play_SoftEnd()
else:
self.VC_Play_End()
usys.print_exception(e)
def _vc_pcm_session_keep_open(self):
- """长对话会话内保留 play_pcm WRITE handle(对话结束/Close 前不 close)。"""
+ """长对话/PTT 会话内保留 play_pcm WRITE handle(Close 前不 close)。"""
try:
if getattr(self, "VC_satrt_flag", 0) != 1:
return False
return False
if int(getattr(self, "VC_play_samplerate", 0)) != 16000:
return False
+ if not (self._vc_is_long_dialogue_mode() or self._vc_is_ptt_mode()):
+ return False
return True
except Exception:
return False
+ def _vc_pcm_prewarm_session_handle(self, via=""):
+ """server.started / 开录前预开 play_pcm,减小 start.pcm 与首包 TTS 延迟。"""
+ try:
+ if not self._vc_pcm_session_keep_open():
+ return False
+ if getattr(self, "play_pcm", None) is not None:
+ return True
+ self._vc_play_pcm_stream_begin(after_file=0)
+ print("[VC] pcm_prewarm via={}".format(via or "-"))
+ return True
+ except Exception as e:
+ usys.print_exception(e)
+ return False
+
def _vc_downlink_stop_playback(self, reason="", force_hard=0):
- """停下行/TTS:长对话优先软停保留 handle;montage/Close/PTT 等走硬关。"""
- if not force_hard and self._vc_pcm_session_keep_open() and self._vc_is_long_dialogue_mode():
+ """停下行/TTS:会话内优先软停保留 handle;Close/montage 等走硬关。"""
+ if not force_hard and self._vc_pcm_session_keep_open():
self._vc_soft_stop_tts_pcm(reason or "downlink_stop")
return
try: