feat(app): an earcon tells the speaker Jarvis took the call

A short two-tone chime, made in code, plays right before each voice answer
starts and at once for a wake word said alone while Jarvis is free; the
question that joins it gets no second one. call.earcon turns it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-12 10:30:55 +09:00
parent 1bebc1c531
commit cefe9b9253
9 changed files with 224 additions and 14 deletions

View File

@@ -92,6 +92,17 @@ impl<B: TtsBackend, S: ClipSink> Playback<B, S> {
id
}
/// Queue a clip the app already has (the earcon) as a request of its own. Returns its id.
pub fn clip(&mut self, pcm: Vec<u8>) -> String {
self.counter += 1;
let id = format!("r{}", self.counter);
self.queue.push_back(Request { id: id.clone(), chunks: BTreeMap::from([(0, pcm)]), next: 0, done: true,
failed: false, played: 0, started: false });
crate::debug_log!("play", "clip id={id} queued={}", self.queue.len());
self.pump();
id
}
/// End a request that will get no audio (the brain gave no answer).
pub fn fail(&mut self, id: &str) {
if let Some(r) = self.queue.iter_mut().find(|r| r.id == id && !r.done) {
@@ -397,4 +408,24 @@ mod tests {
assert_eq!(f.0.borrow().played, vec!["b0"]);
assert_eq!(p.take_events()[0], end(&a, 0, false, true));
}
#[test]
fn a_clip_plays_at_once_then_the_answer_queued_after_it() {
let (mut p, f) = setup();
let cue = p.clip(b("ding"));
let id = p.adopt();
assert_eq!(f.0.borrow().played, vec!["ding"], "the clip needs no worker");
assert!(f.0.borrow().sent.is_empty());
p.audio(&id, 0, b("a0"));
assert_eq!(f.0.borrow().played, vec!["ding"]);
p.clip_ended();
assert_eq!(f.0.borrow().played, vec!["ding", "a0"]);
assert_eq!(p.take_events(), vec![PlaybackEvent::Start(cue.clone()), end(&cue, 1, false, false),
PlaybackEvent::Start(id.clone())]);
// A stop drops a clip still waiting its turn, without asking the worker to cancel it.
let cue2 = p.clip(b("ding"));
p.stop();
assert_eq!(f.0.borrow().cancelled, vec![id.clone()]);
assert!(p.take_events().contains(&end(&cue2, 0, true, false)));
}
}