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:
javis-bot
2026-11-12 12:25:15 +09:00
parent 46e4e75d05
commit b88e20134f
6 changed files with 96 additions and 13 deletions

View File

@@ -30,6 +30,8 @@ pub trait Voice {
fn stop_all(&self);
/// Play the earcon now (queued like speech; dropped by a stop).
fn earcon(&self);
/// A call is still being said (partial transcript): the brain may get ready to answer it.
fn prepare(&self, user: u64, text: &str);
fn ask_addressed(&self, id: &str, user: u64, text: &str) -> bool;
fn ask_rank(&self, id: &str, candidates: &[(String, u64, String)]) -> bool;
/// Have the brain answer a chat message (not spoken); its text comes as `CoreEvent::ReplyText`.
@@ -54,6 +56,9 @@ impl Voice for DiscordCore {
fn earcon(&self) {
DiscordCore::earcon(self);
}
fn prepare(&self, user: u64, text: &str) {
DiscordCore::prepare(self, user, text);
}
fn ask_addressed(&self, id: &str, user: u64, text: &str) -> bool {
DiscordCore::ask_addressed(self, id, user, text)
}
@@ -185,6 +190,22 @@ impl<V: Voice> Conversation<V> {
}
}
/// A partial that already reads as a call (joined to a waiting wake word alone, as its final
/// would be) lets the brain get ready while the speaker is still talking. Not while Jarvis is
/// answering: the call may not be taken, and the brain is busy with the answer.
fn on_partial(&mut self, speaker: u64, partial: &str) {
if !self.answers.is_empty() {
return;
}
let text = match self.wakes.get(&speaker) {
Some((wake, _)) => format!("{} {}", wake.text, partial),
None => partial.to_owned(),
};
if matches!(self.calls.judge(speaker, &text), Call::Request { .. }) && !self.calls.wake_word_only(&text) {
self.voice.prepare(speaker, &text);
}
}
pub fn missed(&self) -> impl Iterator<Item = &Missed> {
self.missed.iter()
}
@@ -199,6 +220,7 @@ impl<V: Voice> Conversation<V> {
}
}
CoreEvent::Chat(m) => self.on_chat(m, now),
CoreEvent::Partial(h, partial) => self.on_partial(h.speaker_id, partial),
CoreEvent::ReplyText { id, text, failed } => {
if let Some((channel, message, asked)) = self.chat_answers.remove(id) {
let late = now >= asked + CHAT_ANSWER_KEPT;
@@ -447,6 +469,7 @@ mod tests {
Cancel(String),
StopAll,
Earcon,
Prepare(u64, String),
Addressed(String, u64),
Rank(String, Vec<String>),
ChatAnswer(String, u64, String),
@@ -474,6 +497,9 @@ mod tests {
fn earcon(&self) {
self.did.borrow_mut().push(Did::Earcon);
}
fn prepare(&self, user: u64, text: &str) {
self.did.borrow_mut().push(Did::Prepare(user, text.into()));
}
fn ask_addressed(&self, id: &str, user: u64, _text: &str) -> bool {
self.did.borrow_mut().push(Did::Addressed(id.into(), user));
true
@@ -553,6 +579,29 @@ mod tests {
assert!(f.take().is_empty(), "missed while busy, and a wake word alone waits silently");
}
fn partial(speaker: u64, text: &str) -> CoreEvent {
CoreEvent::Partial(Heard { speaker_id: speaker, speaker_name: "x".into(), utt: 1 }, text.into())
}
#[test]
fn a_partial_that_reads_as_a_call_lets_the_brain_get_ready() {
let (mut c, f, t) = conv(PolicyKind::First, CallMode::WakeWord);
c.on_event(&partial(A, "자비스 오늘"), ms(t, 0));
c.on_event(&partial(B, "오늘 뭐 먹지"), ms(t, 0)); // not a call
c.on_event(&partial(A, "자비스"), ms(t, 0)); // the name alone: nothing to get ready for
c.on_event(&partial(A, "자비스 멈춰"), ms(t, 0)); // a stop is not answered
assert_eq!(f.take(), vec![Did::Prepare(A, "자비스 오늘".into())]);
// After a wake word said alone, the next utterance's partial is joined to it, as its final.
c.on_event(&fin_utt(B, 1, "자비스"), ms(t, 100));
c.on_event(&partial(B, "지금 몇 시"), ms(t, 300));
assert_eq!(f.take(), vec![Did::Prepare(B, "자비스 지금 몇 시".into())]);
// Not while an answer runs.
c.on_event(&fin(A, "자비스 날씨", 100), ms(t, 400));
f.take();
c.on_event(&partial(A, "자비스 내일은"), ms(t, 500));
assert!(f.take().is_empty());
}
#[test]
fn the_earcon_can_be_turned_off() {
let (mut c, f, t) = conv(PolicyKind::First, CallMode::WakeWord);