]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
vad : return early if no vad segments are detected (#3158)
authorDaniel Bevenius <redacted>
Fri, 16 May 2025 06:50:53 +0000 (08:50 +0200)
committerGitHub <redacted>
Fri, 16 May 2025 06:50:53 +0000 (08:50 +0200)
This commit adds a check to `whisper_full_with_state` and if no VAD
segments are detected, the function will return early.

The motivation for this is that if no VAD segments are detected, the
function will not have any samples to process which can happen if an
audio sample does not contain any speech. I did not test this previously
and only discovered this when updating the stream example.

src/whisper.cpp

index a7e6ef2f81b5ce7b960c26d99e1069f4b068768f..8bad4d1391a5ea6ae3fa8844b5841d30aefdeabd 100644 (file)
@@ -6746,6 +6746,9 @@ int whisper_full_with_state(
             WHISPER_LOG_ERROR("%s: failed to compute VAD\n", __func__);
             return -1;
         }
+        if (vad_n_samples == 0) {
+            return 0;
+        }
         process_samples = vad_samples.data();
         n_process_samples = vad_n_samples;
     }