Repository: speechbrain/speechbrain

Issue:
RuntimeError when processing VAD on short audio
### Describe the bug

When processing a short audio clip with fewer than `sample_rate * large_chunk_size` samples (ex. 480000 for 16kHz with `large_chunk_size=30`, VAD fails trying to access samples out of bound and raise a `RuntimeError: Failed to decode audio.` exception

### Expected behaviour

Processing VAD on short audio clip should not throw an exception

### To Reproduce

https://colab.research.google.com/drive/1eHvZPpIdMJNzlDQIkFgrkQZSjVyhkHPU#scrollTo=fDQ0rwDUGYXK

### Environment Details

Tested against 0.5.16

### Relevant Log Output

```shell
Exception has occurred: RuntimeError       (note: full exception trace is shown but execution is paused at: _run_module_as_main)
Failed to decode audio.
  File "/dev/.venv/lib/python3.10/site-packages/torch/_ops.py", line 692, in __call__
    return self._op(*args, **kwargs or {})
  File "/dev/.venv/lib/python3.10/site-packages/torchaudio/_backend/ffmpeg.py", line 100, in load_audio
    return torch.ops.torchaudio.compat_load(src, format, filter, channels_first)
  File "/dev/.venv/lib/python3.10/site-packages/torchaudio/_backend/ffmpeg.py", line 336, in load
    return load_audio(os.path.normpath(uri), frame_offset, num_frames, normalize, channels_first, format)
  File "/dev/.venv/lib/python3.10/site-packages/torchaudio/_backend/utils.py", line 204, in load
    return backend.load(uri, frame_offset, num_frames, normalize, channels_first, format, buffer_size)
  File "/dev/.venv/lib/python3.10/site-packages/speechbrain/pretrained/interfaces.py", line 1315, in get_speech_prob_file
    large_chunk, fs = torchaudio.load(
  File "/dev/.venv/lib/python3.10/site-packages/speechbrain/pretrained/interfaces.py", line 2121, in get_speech_segments
    prob_chunks = self.get_speech_prob_file(
  File "/dev/verbatim/speaker_diarization/diarize_speakers_speechbrain.py", line 43, in diarize_on_silences
    boundaries = vad_model.get_speech_segments(audio_file)
  File "/dev/verbatim/speech_transcription/transcribe_speech.py", line 271, in execute_for_speaker_and_language
    segments = DiarizeSpeakersSpeechBrain().diarize_on_silences(f"out/{speaker}-{language}.wav")
  File "/dev/verbatim/speech_transcription/transcribe_speech.py", line 324, in execute
    transcription: Transcription = self.execute_for_speaker_and_language(
  File "/dev/verbatim/pipeline.py", line 64, in execute
    transcript = self.transcript_speech.execute(
  File "/dev/tests/test_pipeline.py", line 23, in <module>
    Pipeline(context).execute()
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,
RuntimeError: Failed to decode audio.
```


### Additional Context

_No response_


Discussion:

Resolving patch:
diff --git a/speechbrain/inference/VAD.py b/speechbrain/inference/VAD.py
--- a/speechbrain/inference/VAD.py
+++ b/speechbrain/inference/VAD.py
@@ -109,6 +109,10 @@ def get_speech_prob_file(
         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 @@ def get_speech_prob_file(
             # 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))


Test patch: