From 6b44570b04dd1872ebf0c94cc21ccad13ad49d2c Mon Sep 17 00:00:00 2001 From: Jake Date: Sun, 19 Apr 2026 20:14:17 +0100 Subject: [PATCH] test(transcription): probe whisper-rs 0.16 load + transcribe + initial_prompt --- .../transcription/tests/whisper_rs_smoke.rs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 crates/transcription/tests/whisper_rs_smoke.rs diff --git a/crates/transcription/tests/whisper_rs_smoke.rs b/crates/transcription/tests/whisper_rs_smoke.rs new file mode 100644 index 0000000..366a781 --- /dev/null +++ b/crates/transcription/tests/whisper_rs_smoke.rs @@ -0,0 +1,53 @@ +//! Smoke test: whisper-rs 0.16 loads a GGUF model, transcribes silence, and +//! accepts set_initial_prompt without panicking. +//! +//! Runs only when `KON_WHISPER_TEST_MODEL` is set to the path of a +//! ggml/gguf whisper model on disk. Otherwise the test exits quiet. + +use std::env; + +#[test] +fn whisper_rs_smoke_loads_and_transcribes() { + let model_path = match env::var("KON_WHISPER_TEST_MODEL") { + Ok(p) => p, + Err(_) => { + eprintln!("KON_WHISPER_TEST_MODEL not set — skipping"); + return; + } + }; + + use whisper_rs::{FullParams, SamplingStrategy, WhisperContext, WhisperContextParameters}; + + let ctx = WhisperContext::new_with_params(&model_path, WhisperContextParameters::default()) + .expect("whisper model load"); + + let mut state = ctx.create_state().expect("whisper state"); + + let mut params = FullParams::new(SamplingStrategy::Greedy { best_of: 1 }); + params.set_language(Some("en")); + params.set_initial_prompt("Wren, CORBEL, ADHD"); + params.set_n_threads(2); + params.set_print_special(false); + params.set_print_progress(false); + params.set_print_realtime(false); + + // 1 second of silence at 16 kHz. + let samples = vec![0.0_f32; 16_000]; + + state.full(params, &samples).expect("transcribe"); + + // full_n_segments is infallible in whisper-rs 0.16 — returns c_int. + let n = state.full_n_segments(); + // Silence may produce zero segments; the test only confirms the pipeline runs. + assert!(n >= 0, "segment count must be non-negative"); + + // Exercise the segment accessor API we will use in WhisperRsBackend. + for i in 0..n { + let seg = state + .get_segment(i) + .expect("get_segment returns Some for in-range index"); + let _text: &str = seg.to_str().unwrap_or(""); + let _t0: i64 = seg.start_timestamp(); + let _t1: i64 = seg.end_timestamp(); + } +}