Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions castcorder/crates/castcorder-transcribe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)".
//!
Expand Down Expand Up @@ -92,6 +93,15 @@ fn hiss(secs: f32) -> Vec<f32> {

/// 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;
Expand Down Expand Up @@ -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);
Expand Down