Skip to content

fix: stop Parley hearing itself, show Thinking…, add screen reader cues - #35

Merged
Alorse merged 12 commits into
mainfrom
fix/mic-reopen-after-playback
Sep 29, 2026
Merged

Alorse merged 12 commits into
mainfrom
fix/mic-reopen-after-playback

Conversation

@Alorse

@Alorse Alorse commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Stacked on #34 (fix/single-mic-pipeline).

What changes for the learner

Parley no longer hears itself or background noise as the learner (#27)

  • The mic opens again only after Parley's reply has actually been heard out of the speaker.
    • The server counts its guard from when the reply's audio ends, not from turnComplete. The guard is now 600 ms.
    • The app measures playback on the device itself, including the speaker's output latency (Bluetooth ≈ 250 ms), plus a 250 ms room tail. It sends no mic audio and doesn't show "Listening…" until then.
  • A spoken "turn" heard only as nothing, a single letter, hesitation sounds, or one of the phantoms from the production log ("Mhm.", "un", "b", "Ja.", "RIP", "OII") is not scored or counted. It is logged as noise-turn (length only, no text).
  • Short real answers like "Yes.", "No" or "Two" still count.
  • Voice detection is a little slower to treat a faint sound as the start of speech (START_SENSITIVITY_LOW).
  • Echo cancellation and noise suppression stay on, now pinned by a test.
  • Typed messages are now reviewed as what was typed. Before, every typed message scored "I didn't catch that", because the review saw an empty learner line.

"Thinking…" shows while Parley prepares its answer (#30)

  • It appears 500 ms after the learner's last transcribed words, or at once for typed text, and lasts until the reply starts.
  • More words switch back to "Listening…", and so does no reply at all.
  • Mic frames no longer re-arm it. An open mic streams silence, so that is why it never appeared before.

Screen reader cues (#31)

  • The mic button is "Microphone" with aria-pressed, so its on/off state is announced.
  • A hidden status region says "Your turn." / "Parley is thinking." / "Parley is speaking." on every turn change.
  • The streaming transcript is no longer a live region. Each finished line ("Parley: …", "You: …") and each fetched meaning is announced once, through a hidden log.

Cache version bumped 10 → 11 (index.html, sw.js CACHE_NAME, sw.js?v=). announcer.js was added to the service worker's app shell.

Closes #27
Closes #30
Closes #31

Evidence

Harness: phantom turns. A new test client echoes its own speaker back into the mic, with 250 ms output latency.

streamed reply burst reply (3.8-style)
before 2 phantom turns in 4 s (4 in 8 s, a self-sustaining loop) 2 in 4 s (4 in 8 s)
after 0 0

Browser repro, echo-window / new echo-bluetooth. ms still to be heard when the screen shows "Listening…"; negative means after playback ended.

echo-window (30 ms latency) echo-bluetooth (250 ms) mic frames sent while Parley was audible
original server said listening with +285 / +24 ms still to play — —
server fix only −474, −378, −442 +871, −78 393 / 371
after −399, −298 −259, −190 (final run: −254, −254) 0 / 0

Browser echo-window: "Thinking…" states seen. 0 before, 2 of 2 learner turns after.

Browser, new screen-reader scenario

  • aria-pressed goes false → true → false.
  • The transcript has no aria-live.
  • 8 turn cues over 3 turns.
  • 5 finished lines announced, 0 repeated.

Real API, speech-probe

model case HIGH (before) LOW (after)
gemini-3.8-live quiet voice heard exactly heard exactly (2/2)
gemini-3.8-live own echo only "dog please" (2/2) "please" (2/2)
gemini-3.1-flash-live-preview quiet voice heard exactly heard exactly
gemini-3.1-flash-live-preview own echo only "please" "please"

Every echo-only case was answered "Sorry, I didn't catch that — could you say it again?", both before and after.

Test suites

  • npm run typecheck passes.
  • npm test and /usr/bin/node --import tsx --test test/*.test.js: 177 tests, 176 pass, 0 fail, 1 todo (ACCESS_TOKENS, deliberately left).
  • 154 tests before this branch.
  • The thinking-state harness test is no longer a todo.

Notes

  • "No answer" to a phantom is only partly handled. Gemini starts its reply before Parley knows the full transcript, so a phantom that gets past the gate and the VAD can still get a spoken reply: in practice, the persona's honest "I didn't catch that". It is no longer scored or counted.
  • Harness fix. The fake upstream's per-session audio tag overflowed PCM16 from the 33rd session on, and started throwing once the suite grew. Tags now cycle.
  • Flaky test. In one full run, the existing #13 an upstream that never completes setup… test timed out under load. It passed on every rerun, and it involves no code from this PR.

🤖 Generated with Claude Code

Alorse and others added 12 commits September 29, 2026 09:22
The fake filled session N's audio with N * 1000, which overflows a PCM16
sample from the 33rd upstream session on and throws inside the fake. Tags
now cycle through 1000..32000, and the tests compare through sessionTag().

Co-authored-by: Claude Code <noreply@anthropic.com>
The half-duplex gate opened a fixed 400 ms after turnComplete. A reply sent
in a burst (gemini-3.8-live) or still queued on the phone can play well past
that, so with a Bluetooth speaker the tail of Parley's own voice went back
upstream as a learner turn, which Parley then answered, and so on.

The gate now counts its tail guard from when the reply's audio ends in real
time (already tracked for the turn watchdog), and the guard is 600 ms. The
'listening' state is sent when the gate actually opens.

Harness, a phone that echoes its speaker with ~250 ms output latency:
2 phantom turns in 4 s (4 in 8 s) before, 0 after, streamed and burst.

Refs #27

Co-authored-by: Claude Code <noreply@anthropic.com>
Typed text is never transcribed, so the turn reached the review with an
empty learner line and every typed message scored "I didn't catch that".
The typed text is now the turn's learner text: reviewed, and shown as the
learner's line. This also keeps typed turns apart from the empty spoken
turns #27 ignores.

Refs #27

Co-authored-by: Claude Code <noreply@anthropic.com>
The production journal shows learner turns that were only a sound: empty,
"Mhm.", "un", "b", "Ja.", "RIP", "OII". Each was reviewed and scored.
A spoken turn whose transcript is empty, a single character, only
hesitation sounds, or one of those phantoms is now not a learner turn: no
review, no score, not counted, logged as noise-turn (length only). Typed
turns and short real answers ("Yes.", "Two") are unaffected.

The fake upstream can now transcribe heard speech as a given text.

Refs #27

Co-authored-by: Claude Code <noreply@anthropic.com>
The echo-window scenario now counts the device's output latency in what is
still to be heard when the server reopens the mic, and also records it when
the screen starts saying "Listening…" and how many mic frames were sent
while Parley was still audible. echo-bluetooth runs the same with a 250 ms
output latency, which headless Chrome (30 ms) does not show on its own.

Refs #27

Co-authored-by: Claude Code <noreply@anthropic.com>
…he speaker

In half-duplex mode the client streamed mic audio the whole time and relied
on the server's estimate of when the reply stops playing. On a phone the
real end is later: network, the player's look-ahead and the speaker's own
output latency (Bluetooth: ~250 ms). The client now drops mic frames until
its queued audio, the reported output latency and a 250 ms room tail have
passed, and shows "Listening…" only then. echoCancellation and
noiseSuppression stay on.

Browser repro (echo-window / echo-bluetooth, ms still to be heard when the
screen says Listening; negative = after playback):
  before: -474,-378,-442 / 871,-78; 393 / 371 frames sent while audible
  after:  -399,-298      / -259,-190; 0 / 0 frames sent while audible

Cache version bumped to 11.

Refs #27

Co-authored-by: Claude Code <noreply@anthropic.com>
Refs #27

Co-authored-by: Claude Code <noreply@anthropic.com>
Voice activity detection started a learner turn at the slightest sound.
With START_SENSITIVITY_LOW, speech-probe on the real API:

  gemini-3.8-live   quiet voice  HIGH: heard exactly   LOW: heard exactly (2/2)
                    own echo     HIGH: "dog please"    LOW: "please" (2/2)
  gemini-3.1-flash  quiet voice  heard exactly either way
                    own echo     "please" either way

Every echo-only case is answered with the honest "Sorry, I didn't catch
that", before and after.

Refs #27

Co-authored-by: Claude Code <noreply@anthropic.com>
The thinking timer was re-armed by every mic frame, and an open mic streams
silence the whole time, so 'thinking' never fired. It is now armed by what
the learner says (each transcribed piece) or types (at once): 500 ms after
the last words, and until the reply's audio starts, the client shows
'Thinking…'. More words hand the turn back to 'listening', and so does no
reply at all within the turn watchdog.

Browser repro (echo-window): 'thinking' seen 0 times before, 2 of 2 learner
turns after (speaking,listening,thinking,speaking,...). The harness test
for it is no longer a todo.

Closes #30

Co-authored-by: Claude Code <noreply@anthropic.com>
- The mic button is "Microphone" with aria-pressed, so its on/off state is
  announced (it was only "Toggle microphone").
- A hidden status region gives a short cue on every turn change: "Your
  turn.", "Parley is thinking.", "Parley is speaking.".
- The on-screen transcript is no longer a live region: it is rewritten many
  times per sentence while it streams. Each finished line ("Parley: …",
  "You: …") and a fetched meaning is announced once through a hidden log.

Browser repro (screen-reader): aria-pressed false/true/false, 8 turn cues
over 3 turns, 5 finished lines announced, 0 repeated.

Closes #31

Co-authored-by: Claude Code <noreply@anthropic.com>
Records the mic button's aria-pressed, the turn cues and the finished lines
a screen reader is given during a conversation, and whether the streaming
transcript is a live region.

Refs #31

Co-authored-by: Claude Code <noreply@anthropic.com>
- live.ts: _cancelThinking() clears the thinking timer and flag together,
  instead of three hand-paired copies.
- Tests: QUIET_FRAME next to LOUD_FRAME, the fake's exported output rate,
  one parametrised #27 echo test, and pastGreeting() reused.
- repro-browser: track the latest playback end instead of spreading an
  ever-growing array on every mic frame, and count output latency the way
  AudioPlayer.msUntilHeard() does.

Co-authored-by: Claude Code <noreply@anthropic.com>
@Alorse
Alorse changed the base branch from fix/single-mic-pipeline to main September 29, 2026 16:34
@Alorse
Alorse merged commit c79b4ea into main Sep 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant