Files
faceclaw/tests/microphones-name-guess.test.cjs
James Babcock b50898ea02 Fix a bunch of microphone-related bugs
> Most serious fixes
> - Recordings kept forever: a recording made with captions off, or with "Save captions"
>   off, was transcoded to .m4a and kept indefinitely. No conversation linked to it, so
>   the phone UI never showed it and the retention settings never deleted it. Recording
>   now only happens alongside a saved caption session, and turning captions off ends
>   that session's recording properly.
> - 4-mic mode went silent after a reconnect: a disconnect clears the phone's audio
>   forwarding, and nothing turned it back on, so the app kept showing "Listening (4-mic
>   array)" while hearing nothing. A check every 3 s now restores forwarding and re-sends
>   the config when it has been lost. The normal single-stream mode already recovered on
>   its own.
> - Turning off "4-mic capture" mid-session went silent: it stopped the glasses' stream
>   but never switched to the normal stream. Setup changes now take effect live,
>   including switching between the two modes.
> - Setup changes were undone: after the assistant closed, the app re-sent the config it
>   loaded at launch to the glasses, reverting any changes you'd made since.
> - Startup failures: if the caption engine failed to start, the session got stuck
>   half-running. If the glasses weren't connected, listeners piled up and an empty
>   conversation could be left open. Startup now brings up the microphone first and
>   cleans up properly on failure.
>
> Other fixes
> - Audio quality: the 4-mic beamformer put a small dropout at the start of every 25 ms
>   frame (an audible 40 Hz artifact in the audio feeding captions). Fixed, with a test
>   that fails on the old code.
> - Stale direction data: an arm that stopped sending kept steering the direction
>   estimate and could hold the caption feed on a silent arm.
> - Compass: closing Microphones switched off the Compass app's compass, because both
>   used the same owner name.
> - Speaker database failures:
>   - A failed speaker reload wiped the in-memory list, so the next voice became a
>     duplicate "Speaker N".
>   - A failed speaker insert crashed caption handling; in re-diarize it reassigned
>     transcript lines to a nonexistent speaker.
> - Translation:
>   - A crash path inside the model-download callback is now caught.
>   - Phones set to Hebrew, Indonesian or Yiddish never got translations, because of
>     old-style language codes.
> - Ask questions: once the speaker list grew past the size limit (every unknown voice
>   adds a "Speaker N"), it pushed all transcript lines out of the context sent to the
>   model. When trimming is needed, the oldest lines now go first.
> - Smaller fixes:
>   - The captions view stopped jumping back to live speech after 60 lines.
>   - "This is Dana calling…" was treated as introducing someone else.
>   - A model download that failed to start was stuck at "downloading" until restart.
>   - The developer mic monitor grew without limit while hidden.
2026-10-14 00:56:54 -07:00

88 lines
3.9 KiB
JavaScript

// Introduction-based speaker naming: spoken "I'm Alice" / "this is Bob"
// shapes rename auto-numbered speakers, with guardrails against common
// non-name continuations.
const test = require("node:test");
const assert = require("node:assert/strict");
const {
inferIntroducedName,
isGenericSpeakerName,
pendingApplies,
PENDING_INTRODUCTION_TTL_MS,
} = require("../.test-build/app/apps/microphones/name-guess.js");
test("self-introductions are recognized", () => {
assert.deepEqual(inferIntroducedName("Hi, I'm Alice."), { name: "Alice", kind: "self" });
assert.deepEqual(inferIntroducedName("Hello everyone, my name is Bob Smith and I work here."), {
name: "Bob Smith",
kind: "self",
});
assert.deepEqual(inferIntroducedName("You can call me Kai."), { name: "Kai", kind: "self" });
assert.deepEqual(inferIntroducedName("Good morning, this is Alice speaking."), {
name: "Alice",
kind: "self",
});
// Phone-style self-introductions, including ASR's stray capitalization.
assert.deepEqual(inferIntroducedName("Hey this is Dana calling about the order"), {
name: "Dana",
kind: "self",
});
assert.deepEqual(inferIntroducedName("This is Bob Speaking."), { name: "Bob", kind: "self" });
});
test("third-party introductions are recognized", () => {
assert.deepEqual(inferIntroducedName("Everyone, this is Bob."), { name: "Bob", kind: "third-party" });
assert.deepEqual(inferIntroducedName("Come meet Carol!"), { name: "Carol", kind: "third-party" });
assert.deepEqual(inferIntroducedName("Her name is Dana."), { name: "Dana", kind: "third-party" });
});
test("common non-name continuations do not trigger", () => {
assert.equal(inferIntroducedName("I'm not sure about that."), null);
assert.equal(inferIntroducedName("I'm So excited."), null);
assert.equal(inferIntroducedName("I'm Sorry about earlier."), null);
assert.equal(inferIntroducedName("this is Fine, thanks"), null);
assert.equal(inferIntroducedName("I'm Going to the store."), null);
});
test("states, feelings, and progressive verbs are rejected even capitalized", () => {
assert.equal(inferIntroducedName("I'm Hungry, let's eat."), null);
assert.equal(inferIntroducedName("I'm Wanting to leave soon."), null);
assert.equal(inferIntroducedName("I'm Exhausted after that."), null);
assert.equal(inferIntroducedName("I'm Heading out now."), null);
assert.equal(inferIntroducedName("I'm Nervous about the demo."), null);
assert.equal(inferIntroducedName("I'm Married, by the way."), null);
assert.equal(inferIntroducedName("this is Ridiculous... wait no, this is Awesome"), null);
assert.equal(inferIntroducedName("I'm Waiting outside."), null);
});
test("unusual but real names still pass the heuristic tier", () => {
// The regex tier stays permissive here; the on-device LLM tier gets the
// final say when it's available.
assert.deepEqual(inferIntroducedName("Hi, I'm Ming."), { name: "Ming", kind: "self" });
assert.deepEqual(inferIntroducedName("I'm Priya from the design team."), {
name: "Priya",
kind: "self",
});
});
test("lowercase candidates are rejected (ASR proper nouns are capitalized)", () => {
assert.equal(inferIntroducedName("i'm alice"), null);
});
test("generic speaker names are detected", () => {
assert.equal(isGenericSpeakerName("Speaker 3"), true);
assert.equal(isGenericSpeakerName("Alice"), false);
assert.equal(isGenericSpeakerName("Speaker three"), false);
});
test("pending third-party introduction applies to the right person", () => {
const pending = { name: "Bob", bySpeakerId: 1, atMs: 1000 };
assert.equal(pendingApplies(pending, 2, "Speaker 2", 2000), true);
// Not the introducer themselves.
assert.equal(pendingApplies(pending, 1, "Speaker 1", 2000), false);
// Never overwrites a real name.
assert.equal(pendingApplies(pending, 2, "Dana", 2000), false);
// Expires.
assert.equal(pendingApplies(pending, 2, "Speaker 2", 1000 + PENDING_INTRODUCTION_TTL_MS + 1), false);
});