forge
Explore
Log in

Don't you dare go Hollow

🐛 speech_model downloads a model that is not installed yet; a piece the model heard nothing in is cached too, so a paged transcript stops hearing it again

Browse files at this commit

ef05717660e837286545e2808f7987fcaee6257cAhmet Kaan GümüşParent: ac0c333
crates/mcp/src/tools/listen.rsmodified+5 -17
@@ -283,8 +283,8 @@ fn speech_model(srv: &mut Server, args: &Value) -> Reply {
283283 return Reply::err("a speech model download is already running: speech_model shows its progress");
284284 }
285285 let model = opt_str(args, "model").unwrap_or("base");
286- if let Err(e) = check_model(model) {
287- return Reply::err(e);
286+ if !MODELS.contains(&model) {
287+ return Reply::err(format!("model `{model}` is not one of {}", MODELS.join(", ")));
288288 }
289289 if engine::speech::installed_models().contains(&model) {
290290 return Reply::ok(format!("the {model} speech model is already installed"));
@@ -1217,9 +1217,7 @@ fn review_text(segs: &[&Seg], fps: f64) -> String {
12171217 /// serves it, and a new run is stored under that range. The output depends only on the piece.
12181218 fn run_piece(bin: &Path, p: &Piece, model: &str, lang: &str, hint: &str, fps: f64) -> Result<Vec<Seg>, String> {
12191219 let known = if p.mix { None } else { source_key(&p.path, p.stream, model, lang, hint) };
1220- // An entry with no segments is never served: it is a silent answer, and audible audio gets
1221- // heard again (below) instead of trusting it.
1222- let cached = |dir: &Path| read_exact(dir, p.from, p.to).filter(|raw| has_segments(raw));
1220+ let cached = |dir: &Path| read_exact(dir, p.from, p.to);
12231221 if let Some(raw) = known.as_deref().and_then(|k| cached(&cache_dir().join(k))) {
12241222 return raw_to_segs(&raw, p, fps);
12251223 }
@@ -1244,19 +1242,12 @@ fn run_piece(bin: &Path, p: &Piece, model: &str, lang: &str, hint: &str, fps: f6
12441242 fs::write(&wav.0, wav_bytes(&samples)).map_err(|e| temp_write_error(&wav.0, "writing", e))?;
12451243 let raw = run_stt(bin, &wav.0, model, lang, hint, p.from, &p.label)?;
12461244 let segs = parse_raw(&raw)?.len();
1247- if segs > 0 {
1248- write_entry(&dir, p.from, p.to, &raw);
1249- }
1245+ write_entry(&dir, p.from, p.to, &raw);
12501246 // A segment is one phrase the model timed (start and end), padding included; words are counted inside them.
12511247 eprintln!("transcript {}: done, {segs} segment(s) from the model (phrases with their own start and end, padding included)", p.label);
12521248 raw_to_segs(&raw, p, fps)
12531249 }
12541250
1255-/// True when a cached raw output holds at least one segment.
1256-fn has_segments(raw: &str) -> bool {
1257- parse_raw(raw).is_ok_and(|v| !v.is_empty())
1258-}
1259-
12601251 /// True for audio with no sound in it at all (below -80 dBFS).
12611252 fn is_silent(samples: &[f32]) -> bool {
12621253 samples.iter().all(|s| s.abs() < 1e-4)
@@ -3828,10 +3819,7 @@ mod tests {
38283819 }
38293820
38303821 #[test]
3831- fn an_empty_cached_answer_is_not_served() {
3832- assert!(!has_segments(""));
3833- assert!(!has_segments("\n"));
3834- assert!(has_segments(r#"{"start":0.0,"end":1.0,"text":"hi","words":[]}"#));
3822+ fn digital_silence_is_silent() {
38353823 assert!(is_silent(&[0.0; 16]));
38363824 assert!(!is_silent(&[0.0, 0.2, 0.0]));
38373825 }