diff --git a/speechbrain/inference/VAD.py b/speechbrain/inference/VAD.py index 6ba7db006a65b7d103fc8454b6e0fa62dbf08aab..6f3d55e9c47432603aa7335a25a48e4564eda0ce 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))