Merge pull request #2378 from xinnan-tech/py_update_vad

update: 优化vad判断逻辑
This commit is contained in:
欣南科技
2025-10-22 11:19:33 +08:00
committed by GitHub
4 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -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相关变量
@@ -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
@@ -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)
# 处理语音停止
@@ -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: