Skip to content

Commit c44b60b

Browse files
whisper : call encoder_begin_callback before language auto-detect (#3936)
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.
1 parent 6d0ed91 commit c44b60b

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/whisper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6938,6 +6938,13 @@ int whisper_full_with_state(
69386938
if (params.language == nullptr || strlen(params.language) == 0 || strcmp(params.language, "auto") == 0 || params.detect_language) {
69396939
std::vector<float> probs(whisper_lang_max_id() + 1, 0.0f);
69406940

6941+
if (params.encoder_begin_callback) {
6942+
if (params.encoder_begin_callback(ctx, state, params.encoder_begin_callback_user_data) == false) {
6943+
WHISPER_LOG_ERROR("%s: encoder_begin_callback returned false - aborting\n", __func__);
6944+
return -3;
6945+
}
6946+
}
6947+
69416948
const auto lang_id = whisper_lang_auto_detect_with_state(ctx, state, 0, params.n_threads, probs.data());
69426949
if (lang_id < 0) {
69436950
WHISPER_LOG_ERROR("%s: failed to auto-detect language\n", __func__);

0 commit comments

Comments
 (0)