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
+1 -1
View File
@@ -2,7 +2,7 @@
"package_id": "xylo.hermeven",
"edition": "202601",
"name": "Pepper",
"version": "0.3.0",
"version": "0.4.0",
"min_sdk_version": "0.0.16",
"entrypoint": "index.html",
"permissions": [
+3
View File
@@ -35,6 +35,8 @@ export interface BootOptions {
wake?: boolean;
/** `false` opens at Ready instead of on the menu. For automated simulator runs. */
menu?: boolean;
/** `false`: no words shown while recording. For automated simulator runs. */
livePreview?: boolean;
/** Reload hook, replaceable in tests. */
reload?: () => void;
}
@@ -99,6 +101,7 @@ export async function boot(doc: Document, win: Window, options: BootOptions = {}
// Hands free needs the glasses' microphone: never in the browser preview.
wake: mode === 'even' && options.wake !== false ? {} : null,
menu: options.menu !== false,
livePreview: mode === 'even' && options.livePreview !== false,
...(options.idleExit === false ? { idleExit: null } : typeof options.idleExit === 'object' ? { idleExit: options.idleExit } : {}),
// Development builds mirror diagnostics to the console (visible in the simulator and the
// Even dev console). Diagnostics never contain questions, answers or credentials.
+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. */
+11 -9
View File
@@ -106,20 +106,22 @@ function renderFrame(state: AppState, nowMs: number): HudFrame {
case 'listening': {
const elapsed = state.captureStartedAt === null ? 0 : (nowMs - state.captureStartedAt) / 1000;
const cap = state.captureMaxSeconds;
if (state.captureAuto) {
return {
body: `${agent ? `${agent.name} is listening…` : 'Listening…'}\n\nAsk your question. It is sent when you stop speaking.`,
status: `● REC ${clock(elapsed)} / ${clock(cap)} · Tap: send · 2×: cancel`,
};
}
const title = agent ? `${agent.name} is listening…` : 'Listening…';
const status = state.captureAuto
? `● REC ${clock(elapsed)} / ${clock(cap)} · Tap: send · 2×: cancel`
: `● REC ${clock(elapsed)} / ${clock(cap)} · Tap or release: send · 2×: cancel`;
// Once there are words, they replace the instructions.
if (state.preview) return { body: `${title}\n\n${state.preview}`, status };
return {
body: `${agent ? `${agent.name} is listening…` : 'Listening…'}\n\nRecording stops by itself after ${cap} seconds.`,
status: `● REC ${clock(elapsed)} / ${clock(cap)} · Tap or release: send · 2×: cancel`,
body: state.captureAuto
? `${title}\n\nAsk your question. It is sent when you stop speaking.`
: `${title}\n\nRecording stops by itself after ${cap} seconds.`,
status,
};
}
case 'transcribing':
return { body: 'Transcribing…', status: 'Double-tap: cancel' };
return { body: state.preview ? `Transcribing…\n\n${state.preview}` : 'Transcribing…', status: 'Double-tap: cancel' };
case 'thinking': {
const title = agent ? `${agent.name} is thinking…` : 'Thinking…';
+28 -6
View File
@@ -83,8 +83,15 @@ export interface AppState {
* from what the microphone actually did, so the HUD's indicator is never a guess.
*/
wakeListening: boolean;
/** The question as it was heard, when it was spoken after a name. Shown while the agent works. */
/** The request in flight was spoken (recorded), not typed. */
spoken: boolean;
/** The spoken question as the bridge transcribed it. Shown while the agent works. */
heard: string | null;
/**
* The words of the recording in progress, as far as they have been transcribed. Already cut
* by the controller to what fits the screen. A preview only: it is never what is sent.
*/
preview: string | null;
pages: string[];
pageIndex: number;
/** The answer is a partial one (agent stopped short). Shown on the HUD. */
@@ -119,7 +126,9 @@ export const initialState: AppState = {
captureMaxSeconds: 30,
captureAuto: false,
wakeListening: false,
spoken: false,
heard: null,
preview: null,
pages: [],
pageIndex: 0,
partial: false,
@@ -174,6 +183,8 @@ export type AppEvent =
| { type: 'cancel' }
| { type: 'submit_text'; freshId: string; text: string }
| { type: 'capture_started'; generation: number; at: number }
/** The words so far in the recording being made (already fitted to the screen). */
| { type: 'capture_preview'; generation: number; text: string }
| { type: 'capture_failed'; generation: number; reason: 'mic_refused' | 'mic_stalled' | 'empty' }
| { type: 'capture_limit'; generation: number }
| { type: 'conversation_created'; epoch: number; conversationId: string }
@@ -224,7 +235,9 @@ function clearTurn(state: AppState): AppState {
requestId: null,
captureStartedAt: null,
captureAuto: false,
spoken: false,
heard: null,
preview: null,
pages: [],
pageIndex: 0,
partial: false,
@@ -402,7 +415,7 @@ export function reduce(state: AppState, event: AppEvent): Step {
}
if (state.phase === 'listening' && state.requestId) {
return {
state: { ...state, phase: 'transcribing', captureStartedAt: null },
state: { ...state, phase: 'transcribing', captureStartedAt: null, spoken: true },
effects: [{ type: 'stop_capture_and_submit', generation: state.generation, requestId: state.requestId }],
};
}
@@ -419,7 +432,7 @@ export function reduce(state: AppState, event: AppEvent): Step {
case 'capture_limit': {
if (event.generation !== state.generation || state.phase !== 'listening' || !state.requestId) return same(state);
return {
state: { ...state, phase: 'transcribing', captureStartedAt: null },
state: { ...state, phase: 'transcribing', captureStartedAt: null, spoken: true },
effects: [{ type: 'stop_capture_and_submit', generation: state.generation, requestId: state.requestId }],
};
}
@@ -502,6 +515,11 @@ export function reduce(state: AppState, event: AppEvent): Step {
return same({ ...state, captureStartedAt: event.at });
}
case 'capture_preview': {
if (event.generation !== state.generation || state.phase !== 'listening') return same(state);
return same(event.text === state.preview ? state : { ...state, preview: event.text || null });
}
case 'capture_failed': {
if (event.generation !== state.generation) return same(state);
if (state.phase !== 'listening' && state.phase !== 'transcribing') return same(state);
@@ -522,9 +540,13 @@ export function reduce(state: AppState, event: AppEvent): Step {
if (!IN_FLIGHT.has(state.phase) && state.phase !== 'disconnected') return same(state);
const result = event.result;
if (!result.terminal) {
const phase: Phase =
result.state === 'transcribing' ? 'transcribing' : result.state === 'approval_required' ? 'approval' : 'thinking';
return same({ ...state, phase, disconnectedFrom: null, canResend: false });
// A recording the bridge has accepted but not yet started on is still being transcribed.
const waiting = result.state === 'transcribing' || (result.state === 'accepted' && state.spoken && !result.input_text);
const phase: Phase = waiting ? 'transcribing' : result.state === 'approval_required' ? 'approval' : 'thinking';
// Once the bridge has the transcript of a spoken question, that is what the agent is
// being sent, and it is shown in place of the preview.
const heard = state.heard ?? (state.spoken && !waiting ? (result.input_text ?? null) : null);
return same({ ...state, phase, heard, preview: waiting ? state.preview : null, disconnectedFrom: null, canResend: false });
}
const settled = { ...clearTurn(state), requestId: state.requestId };
switch (result.outcome) {
+1
View File
@@ -25,6 +25,7 @@ const { controller } = await boot(document, window, {
// `?menu=off` opens at Ready instead of on the menu.
wake: !(import.meta.env.DEV && new URLSearchParams(location.search).get('wake') === 'off'),
menu: !(import.meta.env.DEV && new URLSearchParams(location.search).get('menu') === 'off'),
livePreview: !(import.meta.env.DEV && new URLSearchParams(location.search).get('preview') === 'off'),
});
// Development-only convenience for automated simulator runs, where nothing can type into the
+16
View File
@@ -8,6 +8,7 @@ import {
ErrorResponse,
RevokeResponse,
SCHEMA_VERSION,
TranscribeResponse,
TurnResult,
WakeResponse,
type ErrorBody,
@@ -191,6 +192,21 @@ export class BridgeClient {
return this.call(WakeResponse, 'POST', `/v1/wake?${query}`, { binary: args.pcm });
}
/**
* The words in a recording still being made, for showing while the user speaks. Creates
* nothing on the bridge. A bridge without it answers `not_found`.
*/
transcribe(args: { locale: string; pcm: Uint8Array }): Promise<TranscribeResponse> {
const query = new URLSearchParams({
schema_version: String(SCHEMA_VERSION),
locale: args.locale,
encoding: AUDIO_FORMAT.encoding,
sample_rate: String(AUDIO_FORMAT.sampleRate),
channels: String(AUDIO_FORMAT.channels),
});
return this.call(TranscribeResponse, 'POST', `/v1/transcribe?${query}`, { binary: args.pcm });
}
getTurn(requestId: string): Promise<TurnResult> {
return this.call(TurnResult, 'GET', `/v1/turns/${requestId}`) as Promise<TurnResult>;
}
+3 -1
View File
@@ -188,7 +188,9 @@ describe('HUD frames', () => {
if (phase === 'ready') {
return [{ ...base, menu: true }, { ...base, menu: true, ...wake, agents: few }, base, { ...base, notice: 'New conversation' }, { ...base, ...wake }, { ...base, ...wake, agents: few }, { ...base, ...wake, agents: many }, { ...base, ...wake, agents: few, notice: 'New conversation' }];
}
if (phase === 'listening') return [base, { ...base, captureAuto: true }, { ...base, captureAuto: true, agents: few }];
const words = 'what is on my calendar tomorrow and can you move the dentist to Thursday afternoon if that is free';
if (phase === 'listening') return [base, { ...base, captureAuto: true }, { ...base, captureAuto: true, agents: few }, { ...base, agents: few, preview: `… ${words} ${words}` }];
if (phase === 'transcribing') return [base, { ...base, preview: `… ${words} ${words}` }];
if (phase === 'thinking') return [base, { ...base, heard: 'W'.repeat(4000) }, { ...base, agents: few, heard: 'What is on my calendar tomorrow?' }];
if (phase === 'cancelled') return [base, { ...base, ...wake }];
if (phase === 'unpaired') return [base, { ...base, storageFault: true }];