self._vc_handle_asr_empty_ptt(hint, reason)
def _vc_should_soft_recover_empty_asr(self):
- """过短/打断续聊空 ASR:仅重开麦,勿 cancel+synthesis 播「没听清」。"""
if self._vc_asr_empty_soft_recover():
return True
- try:
- if self._vc_is_ptt_mode() and getattr(self, "_turn_has_asr_result", 0) != 1:
- return True
- except Exception:
- pass
- min_ms = 1500
- try:
- if "vc_config" in globals() and vc_config:
- min_ms = int(vc_config.get_int("ASR_EMPTY_MIN_UPLINK_MS", min_ms))
- except Exception:
- pass
- dur = int(getattr(self, "_vc_last_uplink_dur_ms", -1))
- if dur >= 0 and dur < min_ms:
- r = str(getattr(self, "_vc_user_record_open_reason", "") or "")
- if hasattr(self, "_vc_uplink_reason_is_user_key") and self._vc_uplink_reason_is_user_key(r):
- return True
- if r.startswith("key."):
- return True
+ if self._vc_is_ptt_mode() and not getattr(self, "_turn_has_asr_result", 0):
+ return True
+ d = getattr(self, "_vc_last_uplink_dur_ms", -1)
+ if 0 <= d < 1500:
+ r = getattr(self, "_vc_user_record_open_reason", "") or ""
+ return self._vc_uplink_reason_is_user_key(r) or r.startswith("key.")
return False
def _vc_handle_asr_empty_long(self, hint, reason="asr.completed"):
- """长对话:空 ASR 提示播完后复用 sid 重新开麦(蓝慢闪)。"""
- if self._vc_should_soft_recover_empty_asr():
- try:
- self._server_vad_silence = 0
- self._vc_defer_vad_uplink_stop = 0
- self._vc_vad_had_active_after_silence = 0
- self._vc_reopen_uplink_after_empty_hint = 0
- if getattr(self, "VC_record_state_flag", 0):
- self.VC_Speech_End()
- self._vc_clear_stale_record_state("asr.empty/recover")
- self._long_dialogue_publish_listening("asr.empty/recover")
- self.request_uplink_start("asr.empty/recover")
- except Exception:
- pass
- return
try:
self._vc_reopen_uplink_after_empty_hint = 0
if (
pass
def _vc_long_reopen_after_asr_empty_hint(self):
- """长对话:空 ASR 提示 TTS 播完后重新上行(复用当前 sid)。"""
if not getattr(self, "_vc_reopen_uplink_after_empty_hint", 0):
return False
self._vc_reopen_uplink_after_empty_hint = 0
+ if getattr(self, "_turn_has_asr_result", 0) or self._vc_tts_pipeline_busy():
+ return False
+ if getattr(self, "_last_tts_kind", "") != "asr_empty_hint":
+ return False
if not self._vc_is_long_dialogue_mode():
return False
try:
self._vc_clear_stale_record_state("asr.empty/reopen")
self._long_dialogue_publish_listening("asr.empty/reopen")
self.request_uplink_start("asr.empty/reopen")
- print("[VC][ASR] long empty hint done -> reopen uplink")
return True
except Exception as e:
usys.print_exception(e)
return
if getattr(self, "_turn_has_asr_result", 0) != 1:
try:
- print("[VC][ASR] skip think tone (no asr.result this turn)")
+ pass
except Exception:
pass
return
try:
last_ms = int(getattr(self, "_vc_last_think_tone_ms", 0) or 0)
if last_ms and utime.ticks_diff(utime.ticks_ms(), last_ms) < debounce_ms:
- print("[VC][ASR] skip think tone (debounce {}ms)".format(debounce_ms))
+ pass
return
except Exception:
pass
if self._vc_local_play_busy():
try:
- print("[VC][ASR] skip think tone (local_play busy)")
+ pass
except Exception:
pass
return
try:
if self.play_pcm is not None:
pcm_free_pre = self.play_pcm.stream_get_buf_len()
+ pcm_pending_pre = self._vc_pcm_stream_pending_bytes(pcm_free_pre)
else:
- pcm_free_pre = 0
+ pcm_pending_pre = 0
except Exception:
- pcm_free_pre = 0
- pcm_pending_pre = self._vc_pcm_stream_pending_bytes(pcm_free_pre)
+ pcm_pending_pre = max(0, in_len - out_len)
if pcm_pending_pre < 0:
pcm_pending_pre = max(0, in_len - out_len)
played_ok = (out_len >= in_len) or (
is_pcm_empty = (self.play_pcm is None) or (
self.play_pcm is not None and self.play_pcm.stream_is_empty() == 1
)
- pcm_free = 0
+ pcm_free = -1
if self.play_pcm is not None:
try:
pcm_free = self.play_pcm.stream_get_buf_len()
except Exception:
pcm_free = -1
- pcm_pending = self._vc_pcm_stream_pending_bytes(pcm_free)
- if pcm_pending < 0:
- pcm_pending = max(0, in_len - out_len)
+ if self.play_pcm is None:
+ pcm_pending = 0
+ else:
+ pcm_pending = self._vc_pcm_stream_pending_bytes(pcm_free)
+ if pcm_pending < 0:
+ pcm_pending = max(0, in_len - out_len)
bps = self._vc_tts_bytes_per_sec()
fw = getattr(self, "_tts_first_write_ms", 0)