Answers read aloud: Voice on the menu, ElevenLabs voices per agent via the bridge (0.5.0)

- bridge: GET /v1/speech (which agents have a voice) and GET /v1/turns/{id}/speech (MP3 of the
  caller's own finished answer, markup removed, first 900 characters). ElevenLabs adapter; key
  and voice ids from the environment; per-device budget; last three clips kept in memory.
  speech.done / speech.failed log ids, lengths and durations only.
- bridge: forceCloseConnections. A request the client had abandoned kept shutdown waiting for
  ever (also true of /v1/transcribe as deployed). Regression test for both routes.
- client: 'Voice: off/on' on the opening menu when the bridge offers it and the page can play
  sound; off at every launch. With it on, a finished answer is fetched and played; it stops
  when the answer leaves the screen; the app does not leave the glasses while it plays.
- tests: fake provider, fake loudspeaker (tests/integration/voice.test.ts).
- docs: 0006, security 3g-3i, device plan E, 0.4.1 rollout and Dan's sound check report.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Dan
2026-11-29 12:11:38 -08:00
co-authored by Claude Fable 5.2
parent d65beeab77
commit 9874e1bb5b
25 changed files with 1199 additions and 17 deletions
+27 -3
View File
@@ -55,6 +55,10 @@ export interface AppState {
mode: Mode;
/** Hands free can be offered: this build has it, and nothing has said the bridge cannot do it. */
handsFree: boolean;
/** The bridge can read answers aloud and this page can play sound: the menu offers Voice. */
voiceOffered: boolean;
/** Answers are read aloud. Chosen on the menu; off at every launch, never saved. */
voice: boolean;
/**
* The agents the bridge offers, default first. Empty when there is only one (or the bridge
* predates agent selection): nothing about agents is then shown or sent.
@@ -115,6 +119,8 @@ export const initialState: AppState = {
menuIndex: 0,
mode: 'agents',
handsFree: false,
voiceOffered: false,
voice: false,
agents: [],
agentId: null,
generation: 0,
@@ -155,6 +161,8 @@ export type AppEvent =
}
/** Hands free turned out not to be possible (the bridge cannot do it): fall back to Agents. */
| { type: 'handsfree_lost' }
/** Whether answers can be read aloud at all (asked of the bridge after pairing). */
| { type: 'voice_offered'; offered: boolean }
/** The user picked another agent (a swipe at Ready). `conversationId` is that agent's own, if it has one. */
| { type: 'agent_selected'; agentId: string; conversationId: string | null }
/**
@@ -219,8 +227,15 @@ const IDLE: ReadonlySet<Phase> = new Set(['ready', 'answer', 'error', 'cancelled
const IN_FLIGHT: ReadonlySet<Phase> = new Set(['transcribing', 'thinking', 'approval']);
/** The menu's entries, in order. Hands free comes first whenever it can be offered. */
export function menuItems(state: Pick<AppState, 'handsFree'>): Mode[] {
return state.handsFree ? ['handsfree', 'agents'] : ['agents'];
export type MenuItem = Mode | 'voice';
export function menuItems(state: Pick<AppState, 'handsFree' | 'voiceOffered'>): MenuItem[] {
const modes: MenuItem[] = state.handsFree ? ['handsfree', 'agents'] : ['agents'];
return state.voiceOffered ? [...modes, 'voice'] : modes;
}
/** How a menu entry reads. Voice is a switch, so it shows its setting. */
export function menuLabel(item: MenuItem, state: Pick<AppState, 'voice'>): string {
return item === 'voice' ? `Voice: ${state.voice ? 'on' : 'off'}` : MODE_LABEL[item];
}
/** The agent questions go to now, or undefined when the bridge offers no choice. */
@@ -313,6 +328,12 @@ export function reduce(state: AppState, event: AppEvent): Step {
return same({ ...base, phase: base.menu ? 'menu' : 'ready' });
}
case 'voice_offered': {
if (event.offered === state.voiceOffered) return same(state);
const next = { ...state, voiceOffered: event.offered, voice: event.offered && state.voice };
return same({ ...next, menuIndex: Math.min(state.menuIndex, menuItems(next).length - 1) });
}
case 'handsfree_lost': {
if (!state.handsFree) return same(state);
const wasOn = state.mode === 'handsfree';
@@ -403,7 +424,10 @@ export function reduce(state: AppState, event: AppEvent): Step {
case 'activate': {
if (state.phase === 'menu') {
const mode = menuItems(state)[state.menuIndex] ?? 'agents';
const item = menuItems(state)[state.menuIndex] ?? 'agents';
// Voice is a switch: it flips and the menu stays.
if (item === 'voice') return same({ ...state, voice: !state.voice });
const mode: Mode = item;
return same({ ...clearTurn(state), phase: 'ready', mode, generation: state.generation + 1 });
}
if (IDLE.has(state.phase)) {