From 5ebdb9c4d422e5f5440bed148bedc68d9af64cec Mon Sep 17 00:00:00 2001 From: Javier de Jesus Date: Sun, 21 Jun 2026 07:42:41 +0000 Subject: [PATCH] whisper : call encoder_begin_callback before language auto-detect The language auto-detect path in whisper_full_with_state ran the encoder without firing encoder_begin_callback, unlike the main transcription loop. Callers that gate, observe, or abort whisper's encode through the callback had no control over the auto-detection pass. Guard the auto-detect encode with the callback the same way the main loop does. Fixes #3888 --- src/whisper.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/whisper.cpp b/src/whisper.cpp index 2a95bdb1e8a..b2f57a25b00 100644 --- a/src/whisper.cpp +++ b/src/whisper.cpp @@ -6833,6 +6833,13 @@ int whisper_full_with_state( if (params.language == nullptr || strlen(params.language) == 0 || strcmp(params.language, "auto") == 0 || params.detect_language) { std::vector probs(whisper_lang_max_id() + 1, 0.0f); + if (params.encoder_begin_callback) { + if (params.encoder_begin_callback(ctx, state, params.encoder_begin_callback_user_data) == false) { + WHISPER_LOG_ERROR("%s: encoder_begin_callback returned false - aborting\n", __func__); + return -3; + } + } + const auto lang_id = whisper_lang_auto_detect_with_state(ctx, state, 0, params.n_threads, probs.data()); if (lang_id < 0) { WHISPER_LOG_ERROR("%s: failed to auto-detect language\n", __func__);