From 28d0b9f31d54e7c8c99bb3361fbedac80241dc8c Mon Sep 17 00:00:00 2001 From: Gaspard Petit <gaspardpetit@gmail.com> Date: Sun, 4 Feb 2024 17:45:08 -0500 Subject: [PATCH] Fix for issue 2334 : VAD fails on short audio (#2335) * Fix for issue 2334 : VAD fails on short audio * Fix off-by-one boundary logic in VAD processing --- speechbrain/inference/VAD.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/speechbrain/inference/VAD.py b/speechbrain/inference/VAD.py index 6ba7db006..6f3d55e9c 100644 --- a/speechbrain/inference/VAD.py +++ b/speechbrain/inference/VAD.py @@ -109,6 +109,10 @@ class VAD(Pretrained): last_chunk = False begin_sample = 0 while True: + # Check if the current chunk is the last one + if begin_sample + long_chunk_len >= audio_len: + last_chunk = True + # Reading the big chunk large_chunk, fs = torchaudio.load( str(audio_file), @@ -171,10 +175,6 @@ class VAD(Pretrained): # Update counter to process the next big chunk begin_sample = begin_sample + long_chunk_len - # Check if the current chunk is the last one - if begin_sample + long_chunk_len > audio_len: - last_chunk = True - # Converting the list to a tensor prob_vad = torch.cat(prob_chunks, dim=1) last_elem = int(audio_len / (self.time_resolution * sample_rate)) -- GitLab