diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index 4337a488..92043e9b 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -115,9 +115,9 @@ class ConnectionHandler: # vad相关变量 self.client_audio_buffer = bytearray() self.client_have_voice = False + self.client_voice_window = deque(maxlen=5) self.last_activity_time = 0.0 # 统一的活动时间戳(毫秒) self.client_voice_stop = False - self.client_voice_window = deque(maxlen=5) self.last_is_voice = False # asr相关变量 diff --git a/main/xiaozhi-server/core/handle/receiveAudioHandle.py b/main/xiaozhi-server/core/handle/receiveAudioHandle.py index e7b6a138..4eaf9ab1 100644 --- a/main/xiaozhi-server/core/handle/receiveAudioHandle.py +++ b/main/xiaozhi-server/core/handle/receiveAudioHandle.py @@ -33,7 +33,7 @@ async def handleAudioMessage(conn, audio): async def resume_vad_detection(conn): # 等待2秒后恢复VAD检测 - await asyncio.sleep(1) + await asyncio.sleep(2) conn.just_woken_up = False diff --git a/main/xiaozhi-server/core/providers/asr/base.py b/main/xiaozhi-server/core/providers/asr/base.py index 250a25f2..2562f589 100644 --- a/main/xiaozhi-server/core/providers/asr/base.py +++ b/main/xiaozhi-server/core/providers/asr/base.py @@ -68,7 +68,7 @@ class ASRProviderBase(ABC): conn.asr_audio.clear() conn.reset_vad_states() - if len(asr_audio_task) > 15: + if len(asr_audio_task) > 15 or conn.client_listen_mode == "manual": await self.handle_voice_stop(conn, asr_audio_task) # 处理语音停止 diff --git a/main/xiaozhi-server/core/providers/vad/silero.py b/main/xiaozhi-server/core/providers/vad/silero.py index b516d8fb..2263fcb7 100644 --- a/main/xiaozhi-server/core/providers/vad/silero.py +++ b/main/xiaozhi-server/core/providers/vad/silero.py @@ -70,7 +70,9 @@ class VADProvider(VADProviderBase): # 更新滑动窗口 conn.client_voice_window.append(is_voice) - client_have_voice = (conn.client_voice_window.count(True) >= self.frame_window_threshold) + client_have_voice = ( + conn.client_voice_window.count(True) >= self.frame_window_threshold + ) # 如果之前有声音,但本次没有声音,且与上次有声音的时间差已经超过了静默阈值,则认为已经说完一句话 if conn.client_have_voice and not client_have_voice: