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
+3
View File
@@ -73,6 +73,8 @@ export interface BridgeConfig {
turnsPerMinute: number;
/** Wake checks (speech heard while the app is open, tested for a leading agent name). */
wakeChecksPerMinute: number;
/** Live previews of a recording in progress. */
previewsPerMinute: number;
pairingAttemptsPerMinute: number;
};
credentials: {
@@ -327,6 +329,7 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): BridgeConfig {
audioMaxBytes: (captureMaxSeconds + 1) * AUDIO_FORMAT.bytesPerSecond,
turnsPerMinute: int(env, 'HERMEVEN_TURNS_PER_MINUTE', 20, 1, 600),
wakeChecksPerMinute: int(env, 'HERMEVEN_WAKE_CHECKS_PER_MINUTE', 30, 1, 600),
previewsPerMinute: int(env, 'HERMEVEN_PREVIEWS_PER_MINUTE', 60, 1, 600),
pairingAttemptsPerMinute: int(env, 'HERMEVEN_PAIRING_ATTEMPTS_PER_MINUTE', 5, 1, 60),
},
credentials: {
+51 -9
View File
@@ -18,6 +18,7 @@ import {
type ErrorCode,
type ErrorResponse,
type Limits,
type TranscribeResponse,
type WakeResponse,
} from '@hermeven/contracts';
import { DEFAULT_AGENT_ID, type BridgeConfig } from './config.ts';
@@ -148,6 +149,21 @@ export async function buildServer(deps: ServerDeps): Promise<FastifyInstance> {
const wakeLimiter = new RateLimiter(config.limits.wakeChecksPerMinute, 60_000);
/** Devices with a wake check being transcribed: one at a time each. */
const wakeBusy = new Set<string>();
const previewLimiter = new RateLimiter(config.limits.previewsPerMinute, 60_000);
const previewBusy = new Set<string>();
/** The checks shared by the two routes that take a clip of audio and create nothing. */
function audioClip(req: FastifyRequest): { pcm: Buffer; locale: string } {
const contentType = String(req.headers['content-type'] ?? '').split(';')[0]!.trim().toLowerCase();
if (contentType !== 'application/octet-stream') throw new ApiError('unsupported_media', 'Unsupported content type.');
const query = req.query as Record<string, unknown>;
requireVersion(query.schema_version);
if (!check(WakeQuery, query)) throw new ApiError('invalid_request', 'Malformed request.');
const pcm = req.body as Buffer;
if (!Buffer.isBuffer(pcm) || pcm.length === 0) throw new ApiError('invalid_request', 'Audio body is empty.');
if (pcm.length % 2 !== 0) throw new ApiError('invalid_request', 'Audio is not whole 16-bit samples.');
return { pcm, locale: query.locale };
}
function authenticate(req: FastifyRequest): DeviceRow {
const header = req.headers.authorization ?? '';
@@ -320,14 +336,7 @@ export async function buildServer(deps: ServerDeps): Promise<FastifyInstance> {
*/
app.post('/v1/wake', async (req): Promise<WakeResponse> => {
const device = authenticate(req);
const contentType = String(req.headers['content-type'] ?? '').split(';')[0]!.trim().toLowerCase();
if (contentType !== 'application/octet-stream') throw new ApiError('unsupported_media', 'Unsupported content type.');
const query = req.query as Record<string, unknown>;
requireVersion(query.schema_version);
if (!check(WakeQuery, query)) throw new ApiError('invalid_request', 'Malformed wake request.');
const pcm = req.body as Buffer;
if (!Buffer.isBuffer(pcm) || pcm.length === 0) throw new ApiError('invalid_request', 'Audio body is empty.');
if (pcm.length % 2 !== 0) throw new ApiError('invalid_request', 'Audio is not whole 16-bit samples.');
const { pcm, locale } = audioClip(req);
// Nobody can be called by voice (no speech-to-text, or no agent with a usable name): the
// app is told so once and stops sending audio.
if (!deps.stt.configured || !config.agents.some((a) => a.wakeWords.length > 0)) throw new ApiError('not_found', 'Not found.');
@@ -338,7 +347,7 @@ export async function buildServer(deps: ServerDeps): Promise<FastifyInstance> {
const abort = new AbortController();
const timer = setTimeout(() => abort.abort(), config.limits.transcribeDeadlineSeconds * 1000);
try {
const transcript = await deps.stt.transcribe({ pcm, locale: query.locale, signal: abort.signal });
const transcript = await deps.stt.transcribe({ pcm, locale, signal: abort.signal });
const match = matchWake(transcript, config.agents);
if (!match.matched) return { ...none, near_miss: match.nearMiss };
req.log.info({ device_id: device.id, agent_id: match.agentId, name_only: match.text === '' }, 'wake.matched');
@@ -353,6 +362,39 @@ export async function buildServer(deps: ServerDeps): Promise<FastifyInstance> {
}
});
// ----------------------------------------------------------------- preview
/**
* The words in a recording that is still being made, for showing on the glasses while the
* user speaks. Transcribed in memory and dropped: no turn, no row, nothing sent to any agent,
* and the text is never logged. The question that is finally sent is transcribed by its own
* turn, so a preview can never become what the agent receives.
*/
app.post('/v1/transcribe', async (req, reply): Promise<TranscribeResponse> => {
const device = authenticate(req);
const { pcm, locale } = audioClip(req);
if (!deps.stt.configured) throw new ApiError('not_found', 'Not found.');
if (previewBusy.has(device.id) || !previewLimiter.take(device.id)) throw new ApiError('rate_limited', 'Too many requests. Wait a moment.');
previewBusy.add(device.id);
const abort = new AbortController();
const timer = setTimeout(() => abort.abort(), config.limits.transcribeDeadlineSeconds * 1000);
// The app has stopped waiting (the recording was sent or cancelled): stop too, so the real
// transcription is not kept waiting behind a preview nobody will see.
reply.raw.on('close', () => {
if (!reply.raw.writableEnded) abort.abort();
});
try {
const text = await deps.stt.transcribe({ pcm, locale, signal: abort.signal });
return { schema_version: SCHEMA_VERSION, text: text.trim().slice(0, config.limits.textMaxChars) };
} catch (err) {
// No preview this time. The recording itself is unaffected.
req.log.warn({ device_id: device.id, err_name: err instanceof Error ? err.name : 'unknown' }, 'preview.transcription_failed');
return { schema_version: SCHEMA_VERSION, text: '' };
} finally {
clearTimeout(timer);
previewBusy.delete(device.id);
}
});
app.get('/v1/turns/:requestId', async (req) => {
const device = authenticate(req);
const { requestId } = req.params as { requestId: string };