From c4fd60fcaa6a62c8f6afe58ce1611fc59f019d19 Mon Sep 17 00:00:00 2001 From: Matt Palmer Date: Tue, 2 Apr 2024 15:57:31 -0400 Subject: [PATCH] Set audio_ctx according to recommendation in whisper.cpp repo https://github.com/ggerganov/whisper.cpp/issues/1855 --- src/whisper.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/whisper.rs b/src/whisper.rs index a3cdb88..f4b2194 100644 --- a/src/whisper.rs +++ b/src/whisper.rs @@ -33,6 +33,15 @@ impl Whisper { let mut params = FullParams::new(whisper_rs::SamplingStrategy::Greedy { best_of: 1 }); params.set_max_len(1); params.set_split_on_word(true); + params.set_audio_ctx({ + let blen = data.as_ref().len(); + let audio_secs = blen as f32 / 16.0; + if audio_secs > 30.0 { + 1500 + } else { + (audio_secs as i32) / 30 * 1500 + 128 + } + }); match state.full(params, data.as_ref()) { Ok(0) => {}