Words on the glasses while recording, and "Heard:" for spoken questions (0.4.0)

While a recording is being made the app sends the recording so far to a
new bridge route, POST /v1/transcribe, about every half second of new
audio and one request at a time, and draws the words under "... is
listening…", newest words kept in view. No new service: it is the Whisper
already in the bridge. A preview is only ever drawn. The question is
transcribed again by its own turn, so a preview can never be what the
agent receives.

After sending, the last preview stays under "Transcribing…", then "Heard:"
shows the transcript the bridge gave the agent, now for every spoken
question (it was hands free only). The reducer tracks `spoken` explicitly
and treats an accepted, not yet transcribed recording as transcribing.

Bridge: /v1/transcribe needs a device credential, shares the audio checks
with /v1/wake, runs one at a time per device within
HERMEVEN_PREVIEWS_PER_MINUTE (60), creates nothing and logs no text.
An older bridge answers 404 and the client stops asking.

Simulator: a scenario that launches the app as shipped (menu, hands free)
as Round 18 required. A diagnostics note marks when listening for a name
starts and stops.

Also records the 0.3.0 deployment, upload and Dan's device report
(docs/evidence/device/2026-11-28.md), and decision 0005.

Not reviewed, not deployed, not uploaded, not device-tested.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Dan
2026-11-28 11:44:36 -08:00
co-authored by Claude Fable 5.2
parent 44ea1148c3
commit f9946a027a
19 changed files with 531 additions and 32 deletions
+92 -1
View File
@@ -112,6 +112,20 @@ export interface WakeTiming {
pauseMs: number;
}
export interface PreviewTiming {
/** Nothing is transcribed until this much has been recorded. */
firstMs: number;
/** A new preview is asked for once this much more has been recorded (and the last one is back). */
stepMs: number;
/** After a failure, previews are not asked for again for this long. */
pauseMs: number;
}
export const DEFAULT_PREVIEW_TIMING: PreviewTiming = { firstMs: 700, stepMs: 500, pauseMs: 5000 };
/** Lines of the body left for the words under the "… is listening…" title and a blank line. */
const PREVIEW_LINES = HUD.bodyLines - 2;
export const DEFAULT_WAKE_TIMING: WakeTiming = {
commandEndSilenceMs: 1200,
armTimeoutMs: 6000,
@@ -166,6 +180,11 @@ export interface ControllerOptions {
* a tap.
*/
wake?: Partial<WakeTiming> | null;
/**
* Show the words of a recording while it is being made: every so often the recording so far
* is sent to the bridge for transcription. Off unless set.
*/
livePreview?: boolean | Partial<PreviewTiming>;
/**
* Open on a menu (Hands free, Agents) instead of at Ready; double tap at Ready returns to it.
* Without it the app opens at Ready, in hands-free mode if `wake` is given.
@@ -189,6 +208,8 @@ interface Capture {
startedAt: number;
/** The whole question was already spoken before the recording began: send it as it is. */
complete: boolean;
/** How much of it had been recorded when the last live preview was asked for. */
previewedBytes: number;
}
type PendingInput = { requestId: string; kind: 'text'; text: string } | { requestId: string; kind: 'audio'; pcm: Uint8Array };
@@ -253,6 +274,13 @@ export class Controller {
/** Set while a long press that STARTED a recording is still held down. */
private heldPress: { generation: number; at: number } | null = null;
// ---- words shown while recording (unused when `preview` is null)
private readonly preview: PreviewTiming | null;
private previewBusy = false;
private previewPausedUntil = 0;
/** The bridge said it cannot do previews (or is too old): stop asking for this session. */
private previewUnsupported = false;
// ---- listening for a name (all unused when `wake` is null)
private readonly wake: WakeTiming | null;
private readonly segmenter = new SpeechSegmenter();
@@ -287,6 +315,7 @@ export class Controller {
this.exitRetryMs = options.exitRetryMs ?? 3_000;
this.exitAttempts = Math.max(1, options.exitAttempts ?? 4);
this.wake = options.wake ? { ...DEFAULT_WAKE_TIMING, ...options.wake } : null;
this.preview = options.livePreview ? { ...DEFAULT_PREVIEW_TIMING, ...(options.livePreview === true ? {} : options.livePreview) } : null;
}
// ------------------------------------------------------------------ public
@@ -436,7 +465,10 @@ export class Controller {
await this.device.stopMic();
}
const listening = this.micOpen && this.wakeActive();
if (listening !== this.state.wakeListening) this.dispatch({ type: 'wake_status', listening });
if (listening !== this.state.wakeListening) {
this.note('wake', listening ? 'listening for a name' : 'stopped listening');
this.dispatch({ type: 'wake_status', listening });
}
return this.micOpen;
});
this.micChain = run.then(
@@ -917,6 +949,7 @@ export class Controller {
auto,
startedAt: this.now(),
complete: false,
previewedBytes: 0,
};
if (auto) {
// The name was recognised a moment after it was said, and the speaker may not have
@@ -993,6 +1026,64 @@ export class Controller {
this.dispatch({ type: 'capture_limit', generation: capture.generation });
}
if (capture.auto && !capture.limitSent) this.followAutoCapture(capture, pcm);
if (!capture.limitSent) this.maybePreview(capture);
}
/**
* Ask the bridge for the words so far, one request at a time. What comes back is only ever
* drawn: the recording that is finally sent is transcribed again as part of its own turn.
*/
private maybePreview(capture: Capture): void {
const timing = this.preview;
const client = this.client;
if (!timing || !client || this.previewUnsupported || this.previewBusy || this.now() < this.previewPausedUntil) return;
if (this.status?.stt_configured === false) return;
const ms = (bytes: number) => (bytes / AUDIO_FORMAT.bytesPerSecond) * 1000;
if (ms(capture.bytes) < timing.firstMs) return;
if (capture.previewedBytes > 0 && ms(capture.bytes - capture.previewedBytes) < timing.stepMs) return;
capture.previewedBytes = capture.bytes;
const usable = capture.bytes - (capture.bytes % 2);
const pcm = new Uint8Array(usable);
let offset = 0;
for (const chunk of capture.chunks) {
const take = Math.min(chunk.length, usable - offset);
pcm.set(chunk.subarray(0, take), offset);
offset += take;
}
this.previewBusy = true;
void client
.transcribe({ pcm, locale: this.options.locale })
.then(
(result) => {
// Only for the recording it was made from, and only while that is still being made.
if (this.capture !== capture || this.stale(capture.generation) || this.state.phase !== 'listening') return;
if (result.text) this.dispatch({ type: 'capture_preview', generation: capture.generation, text: this.fitPreview(result.text) });
},
(err) => {
if (err instanceof BridgeApiError && err.body.code === 'not_found') {
this.previewUnsupported = true;
this.note('preview', 'this bridge cannot show words while recording');
} else {
// Busy, over the limit or unreachable: the recording carries on without a preview.
this.previewPausedUntil = this.now() + (err instanceof BridgeApiError && err.body.code === 'rate_limited' ? 1000 : timing.pauseMs);
if (!(err instanceof BridgeApiError && err.body.code === 'rate_limited')) this.note('preview', `not available just now: ${describe(err)}`);
}
},
)
.finally(() => {
this.previewBusy = false;
});
}
/** The end of the text that fits under the title: the newest words are the ones to see. */
private fitPreview(text: string): string {
const words = toPlainText(text).split(/\s+/).filter(Boolean);
let from = 0;
for (;;) {
const shown = (from > 0 ? '… ' : '') + words.slice(from).join(' ');
if (from >= words.length - 1 || (shown.length <= 600 && this.options.measure(shown, BODY_BOX.innerWidth) <= PREVIEW_LINES)) return shown.slice(-600);
from += Math.max(1, Math.ceil((words.length - from) / 8));
}
}
/** A recording started by name: send when the speaker stops, give up if nobody speaks. */