feat(app): a call still being said lets the brain get ready
A partial transcript that call detection already reads as a request is sent to the worker as prepare, so the intent judge runs while the speaker talks. The live round trip now times the earcon and the answer's own sound apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -72,7 +72,8 @@ struct Ears {
|
||||
jarvis: u64,
|
||||
ssrc: Arc<Mutex<HashMap<u32, u64>>>,
|
||||
stream: Arc<Mutex<Option<SpeakerStream<OpusFrames>>>>,
|
||||
first_audible: Arc<Mutex<Option<Instant>>>,
|
||||
/// When each audible 20 ms frame arrived (the earcon first, then the answer).
|
||||
audible: Arc<Mutex<Vec<Instant>>>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -95,7 +96,7 @@ impl VoiceHandler for Ears {
|
||||
// Audible: louder than -36 dBFS. Silence frames do not count.
|
||||
let rms = (f.iter().map(|&x| f64::from(x).powi(2)).sum::<f64>() / f.len().max(1) as f64).sqrt();
|
||||
if rms > 500.0 {
|
||||
self.first_audible.lock().unwrap().get_or_insert_with(Instant::now);
|
||||
self.audible.lock().unwrap().push(Instant::now());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -261,7 +262,7 @@ async fn conversation_round_trip_on_real_discord() {
|
||||
// The previous answer is over before the next question.
|
||||
until("Jarvis to finish speaking", 60_000, || !core.speaking()).await;
|
||||
let before = events.lock().unwrap().len();
|
||||
*ears.first_audible.lock().unwrap() = None;
|
||||
ears.audible.lock().unwrap().clear();
|
||||
let track = call.lock().await.play_only_input(Input::from(wav.clone()));
|
||||
let deadline = Instant::now() + Duration::from_secs(5);
|
||||
let started = loop {
|
||||
@@ -305,8 +306,18 @@ async fn conversation_round_trip_on_real_discord() {
|
||||
text: finals.iter().map(|(_, f)| f.text.as_str()).collect::<Vec<_>>().join(" | "),
|
||||
stt_ms: f.stt_ms,
|
||||
}));
|
||||
let speak_start = ev.iter().find_map(|(t, e)| matches!(e, CoreEvent::SpeakStart(_)).then_some(*t));
|
||||
let first_sound = *ears.first_audible.lock().unwrap();
|
||||
// The first sound is the earcon; the answer's own sound starts after its SpeakStart.
|
||||
let reply_id = ev.iter().find_map(|(_, e)| match e {
|
||||
CoreEvent::ReplyText { id, .. } => Some(id.clone()),
|
||||
_ => None,
|
||||
});
|
||||
let speak_start = ev.iter().find_map(|(t, e)| match e {
|
||||
CoreEvent::SpeakStart(id) if Some(id) == reply_id.as_ref() => Some(*t),
|
||||
_ => None,
|
||||
});
|
||||
let audible = ears.audible.lock().unwrap().clone();
|
||||
let first_sound = audible.first().copied();
|
||||
let answer_sound = speak_start.and_then(|s| audible.iter().copied().find(|t| *t >= s));
|
||||
rows.push(json!({
|
||||
"round": round, "question": text,
|
||||
"heard": final_ev.as_ref().map(|(_, f)| f.text.clone()),
|
||||
@@ -316,6 +327,7 @@ async fn conversation_round_trip_on_real_discord() {
|
||||
"answer_text_ms": ms(reply.as_ref().map(|r| r.0)),
|
||||
"speak_start_ms": ms(speak_start),
|
||||
"first_sound_ms": ms(first_sound),
|
||||
"answer_sound_ms": ms(answer_sound),
|
||||
"spoken": finished,
|
||||
}));
|
||||
println!("{phase} {}", rows.last().unwrap());
|
||||
@@ -324,12 +336,17 @@ async fn conversation_round_trip_on_real_discord() {
|
||||
}
|
||||
stop.store(true, Ordering::Relaxed);
|
||||
let load_finals = match load { Some(h) => Some(h.await.unwrap()), None => None };
|
||||
let mut sound: Vec<i64> = rows.iter().filter_map(|r| r["first_sound_ms"].as_i64()).collect();
|
||||
sound.sort_unstable();
|
||||
let pick = |q: f64| sound.get(((sound.len() as f64 - 1.0) * q).round() as usize).copied();
|
||||
let stats = |key: &str| {
|
||||
let mut v: Vec<i64> = rows.iter().filter_map(|r| r[key].as_i64()).collect();
|
||||
v.sort_unstable();
|
||||
let pick = |q: f64| v.get(((v.len() as f64 - 1.0) * q).round() as usize).copied();
|
||||
(v.len(), json!({"min": v.first(), "median": pick(0.5), "p90": pick(0.9), "max": v.last()}))
|
||||
};
|
||||
let (answered, answer_sound) = stats("answer_sound_ms");
|
||||
report.insert(phase.into(), json!({
|
||||
"rows": rows, "answered": sound.len(), "asked": rows.len(),
|
||||
"first_sound_ms": {"min": sound.first(), "median": pick(0.5), "p90": pick(0.9), "max": sound.last()},
|
||||
"rows": rows, "answered": answered, "asked": rows.len(),
|
||||
"first_sound_ms": stats("first_sound_ms").1,
|
||||
"answer_sound_ms": answer_sound,
|
||||
"background_finals": load_finals,
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user