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
This commit is contained in:
Javier de Jesus 2026-06-21 07:42:41 +00:00
parent 6fc7c33b4c
commit 5ebdb9c4d4
1 changed files with 7 additions and 0 deletions

View File

@ -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<float> 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__);