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 {
283 return Reply::err("a speech model download is already running: speech_model shows its progress");283 return Reply::err("a speech model download is already running: speech_model shows its progress");
284 }284 }
285 let model = opt_str(args, "model").unwrap_or("base");285 let model = opt_str(args, "model").unwrap_or("base");
286- if let Err(e) = check_model(model) {286+ if !MODELS.contains(&model) {
287- return Reply::err(e);287+ return Reply::err(format!("model `{model}` is not one of {}", MODELS.join(", ")));
288 }288 }
289 if engine::speech::installed_models().contains(&model) {289 if engine::speech::installed_models().contains(&model) {
290 return Reply::ok(format!("the {model} speech model is already installed"));290 return Reply::ok(format!("the {model} speech model is already installed"));
@@ -1217,9 +1217,7 @@ fn review_text(segs: &[&Seg], fps: f64) -> String {
1217 /// serves it, and a new run is stored under that range. The output depends only on the piece.1217 /// serves it, and a new run is stored under that range. The output depends only on the piece.
1218 fn run_piece(bin: &Path, p: &Piece, model: &str, lang: &str, hint: &str, fps: f64) -> Result<Vec<Seg>, String> {1218 fn run_piece(bin: &Path, p: &Piece, model: &str, lang: &str, hint: &str, fps: f64) -> Result<Vec<Seg>, String> {
1219 let known = if p.mix { None } else { source_key(&p.path, p.stream, model, lang, hint) };1219 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 gets1220+ let cached = |dir: &Path| read_exact(dir, p.from, p.to);
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));
1223 if let Some(raw) = known.as_deref().and_then(|k| cached(&cache_dir().join(k))) {1221 if let Some(raw) = known.as_deref().and_then(|k| cached(&cache_dir().join(k))) {
1224 return raw_to_segs(&raw, p, fps);1222 return raw_to_segs(&raw, p, fps);
1225 }1223 }
@@ -1244,19 +1242,12 @@ fn run_piece(bin: &Path, p: &Piece, model: &str, lang: &str, hint: &str, fps: f6
1244 fs::write(&wav.0, wav_bytes(&samples)).map_err(|e| temp_write_error(&wav.0, "writing", e))?;1242 fs::write(&wav.0, wav_bytes(&samples)).map_err(|e| temp_write_error(&wav.0, "writing", e))?;
1245 let raw = run_stt(bin, &wav.0, model, lang, hint, p.from, &p.label)?;1243 let raw = run_stt(bin, &wav.0, model, lang, hint, p.from, &p.label)?;
1246 let segs = parse_raw(&raw)?.len();1244 let segs = parse_raw(&raw)?.len();
1247- if segs > 0 {1245+ write_entry(&dir, p.from, p.to, &raw);
1248- write_entry(&dir, p.from, p.to, &raw);
1249- }
1250 // A segment is one phrase the model timed (start and end), padding included; words are counted inside them.1246 // A segment is one phrase the model timed (start and end), padding included; words are counted inside them.
1251 eprintln!("transcript {}: done, {segs} segment(s) from the model (phrases with their own start and end, padding included)", p.label);1247 eprintln!("transcript {}: done, {segs} segment(s) from the model (phrases with their own start and end, padding included)", p.label);
1252 raw_to_segs(&raw, p, fps)1248 raw_to_segs(&raw, p, fps)
1253 }1249 }
1254 1250
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-
1260 /// True for audio with no sound in it at all (below -80 dBFS).1251 /// True for audio with no sound in it at all (below -80 dBFS).
1261 fn is_silent(samples: &[f32]) -> bool {1252 fn is_silent(samples: &[f32]) -> bool {
1262 samples.iter().all(|s| s.abs() < 1e-4)1253 samples.iter().all(|s| s.abs() < 1e-4)
@@ -3828,10 +3819,7 @@ mod tests {
3828 }3819 }
3829 3820
3830 #[test]3821 #[test]
3831- fn an_empty_cached_answer_is_not_served() {3822+ fn digital_silence_is_silent() {
3832- assert!(!has_segments(""));
3833- assert!(!has_segments("\n"));
3834- assert!(has_segments(r#"{"start":0.0,"end":1.0,"text":"hi","words":[]}"#));
3835 assert!(is_silent(&[0.0; 16]));3823 assert!(is_silent(&[0.0; 16]));
3836 assert!(!is_silent(&[0.0, 0.2, 0.0]));3824 assert!(!is_silent(&[0.0, 0.2, 0.0]));
3837 }3825 }