From e14e1be7d82f93e6a3b56eae45e09f9bb2ba9fe4 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 15 May 2025 13:38:53 +0200 Subject: [PATCH] vad : return early if no vad segments are detected 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/whisper.cpp b/src/whisper.cpp index ad4e7a12d71..8c16928eaeb 100644 --- a/src/whisper.cpp +++ b/src/whisper.cpp @@ -6735,6 +6735,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; }