diff --git a/castcorder/crates/castcorder-transcribe/src/lib.rs b/castcorder/crates/castcorder-transcribe/src/lib.rs index cb5096e..ea25f02 100644 --- a/castcorder/crates/castcorder-transcribe/src/lib.rs +++ b/castcorder/crates/castcorder-transcribe/src/lib.rs @@ -5,7 +5,8 @@ //! nothing is downloaded). With the `vulkan` feature it uses the GPU when one //! is usable and the CPU otherwise. Each utterance is transcribed on its own //! (no context carried over), greedy, English, at temperature 0, so the same -//! audio gives the same text. Non-speech is dropped: segments whisper itself +//! audio gives the same text, except that a decode that loops is retried +//! warmer (whisper.cpp's repetition check, see `transcribe`). Non-speech is dropped: segments whisper itself //! rates as probably not speech, and markers such as "[BLANK_AUDIO]" or //! "(music)". //! @@ -92,6 +93,15 @@ fn hiss(secs: f32) -> Vec { /// A segment whisper rates at least this likely to be non-speech is dropped. const NO_SPEECH: f32 = 0.6; +/// How much warmer each retry of a decode that looped is (whisper.cpp's own +/// default); a loop is retried at 0.2, 0.4, ... up to 1.0. +const TEMPERATURE_STEP: f32 = 0.2; +/// A decode whose token entropy is under this is a loop (whisper.cpp's +/// default, the same as OpenAI's compression ratio check of 2.4). +const REPETITION_ENTROPY: f32 = 2.4; +/// Average log probability under which whisper.cpp would also retry warmer: +/// set so low it never fires, so only a loop causes a retry. +const NEVER_BY_CONFIDENCE: f32 = -100.0; /// Audio quieter than this (RMS, about -50 dBFS) is not given to the model: /// whisper invents words for near-silence. const QUIET_RMS: f32 = 0.003; @@ -212,8 +222,16 @@ impl Whisper { p.set_language(Some("en")); p.set_translate(false); p.set_no_context(true); + // Greedy at temperature 0 can get stuck in a loop ("Thank you. Thank + // you. ..."). whisper.cpp's own guard is on: a decode whose tokens are + // too repetitive (entropy under the threshold) is run again at a + // warmer temperature, up to 1.0. The other trigger, a low average log + // probability, is off (threshold far below any real value), so plain + // quiet or unclear speech still decodes once, at temperature 0. p.set_temperature(0.0); - p.set_temperature_inc(0.0); + p.set_temperature_inc(TEMPERATURE_STEP); + p.set_entropy_thold(REPETITION_ENTROPY); + p.set_logprob_thold(NEVER_BY_CONFIDENCE); p.set_suppress_blank(true); p.set_suppress_nst(true); p.set_print_progress(false);