Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
391c5f3
CONTRACT: feat(ui-server): register selectable dictation providers (WIP)
schlessera Nov 8, 2026
9a9ce76
CONTRACT: feat(ui-server): complete selectable dictation provider proof
schlessera Nov 8, 2026
9c08f9b
CONTRACT: fix(ui-server): allow bound dictation uploads across origins
schlessera Nov 8, 2026
bfb4e0f
CONTRACT: feat(ui-server,ui-react): add Gemini 3.5 Transcribe Live di…
schlessera Nov 8, 2026
63251dc
fix(ui-server): keep legacy speech misconfiguration a route error, no…
schlessera Nov 8, 2026
fe4dce3
Merge remote-tracking branch 'origin/main' into fix/3707-review
schlessera Nov 8, 2026
e5ccfb8
Merge remote-tracking branch 'origin/main' into fix/3717-review
schlessera Nov 8, 2026
8d11639
docs: repair dictation citations moved by the speech registry
schlessera Nov 8, 2026
85a6924
CONTRACT: fix(ui-server,ui-react): send the REST auth-token shape and…
schlessera Nov 8, 2026
12d7f1c
Merge remote-tracking branch 'origin/main' into fix/3707-review
schlessera Nov 8, 2026
5c7c6dc
Merge #3707 registry into the Gemini dictation branch
schlessera Nov 8, 2026
0e5e26a
feat(ui-server): built-in dictation providers disclose their label an…
schlessera Nov 8, 2026
8a473ac
Merge remote-tracking branch 'origin/main' into int/3708-registry
schlessera Nov 8, 2026
704ed66
docs(changeset): describe Gemini registration under the dictation reg…
schlessera Nov 8, 2026
37a6644
Merge remote-tracking branch 'origin/main' into int/3708-registry
schlessera Nov 8, 2026
cc2ed8f
Merge remote-tracking branch 'origin/main' into int/3708-registry
schlessera Nov 8, 2026
f0e12ab
Merge remote-tracking branch 'origin/main' into int/3708-registry
schlessera Nov 8, 2026
336d4b9
Merge remote-tracking branch 'origin/main' into int/3708-registry
schlessera Nov 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/gemini-transcribe-live-dictation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-server": minor
"@schlessera/brain-ui-react": minor
---

Add Google Gemini 3.5 Transcribe Live as a built-in dictation provider (#3708). `GEMINI_API_KEY` registers it as the selectable dictation provider `gemini`. A key never makes it the host default: it is used through `VOICE_PROVIDER=gemini`, a saved Voice-settings choice, or as the only registered provider, and Deepgram stays the host default when its key is set. The Deepgram and browser-speech built-ins now also disclose a `label` and `destination` in `GET /voice/providers`. The key stays on the server: each take mints a single-use ephemeral token whose constraints lock `gemini-3.5-transcribe-live`, text output and the transcription config (SMART by default, the brain's keyterms as vocabulary, at most 100 terms of 64 bytes). Any mint failure is the session route's 500 `{ error: "Gemini dictation session failed" }`, with neither the key nor Google's text. The browser's `gemini` client streams 16 kHz mono PCM16 in 100 ms frames, resampled from the hardware rate, with bounded pre-setup buffering, handshake, upload backlog and Done drain; interim text replaces the partial and each final commits once. Gemini cannot transcribe saved recordings. Live conversation's microphone capture now shares the same worklet and resampler, unchanged byte for byte.

The server requires `label` and `destination`, when supplied, to be nonempty strings, and `runSpeechProviderContract` checks the optional SDK fields' types and that a SMART provider mints for both modes. Keyless tests prove protocol and resource behaviour only; acceptance by Google, accuracy and latency are qualified separately.
1 change: 1 addition & 0 deletions api-report/ui-server.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,7 @@ signatures (every public export and the types it is made of)
export interface VoiceConfig {
provider: string | null;
deepgramApiKey: string | null;
geminiApiKey?: string | null;
keytermLimit: number;
cacheDir: string;
}
Expand Down
4 changes: 2 additions & 2 deletions docs/extending/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ first-party code: `EMBEDDING_PROVIDERS`, `COMPLETION_PROVIDERS`,
`@schlessera/brain-compute-boat` package and is unavailable until it ships), `BUILTIN_EMITTERS` in
`packages/core/src/lib/skills/index.ts`, the `FIRST_PARTY_BACKENDS` table in
`packages/ui-server/src/agent/backend.ts`, and — the same thing written by hand
rather than as a registry — the two `VOICE_PROVIDER` names `pickSpeechProvider`
accepts in `packages/ui-server/src/voice/speech-providers.ts`.
rather than as a registry — the built-in dictation providers `configuredSpeechProviders` registers in
`packages/ui-server/src/voice/speech-providers.ts`.

Promotion is therefore only a question for some of the seams. The two client
seams are not in it: a `ToolRenderer` pack and an `AsrClient` are registered by
Expand Down
69 changes: 68 additions & 1 deletion docs/extending/speech.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ See the [HTTP specification](../http-api.md#selectable-dictation-providers) for
settings revisions, exact selection errors and the no-fallback rule. Gemini's
built-in factory is implemented separately in #3708; no placeholder is registered.

The four streaming capabilities are boolean. Optional `savedAudio` is derived from a callable `transcribeRecording`; a contradictory explicit declaration is rejected. `streaming` describes streaming recognition,
The four streaming capabilities are boolean. Optional `savedAudio` is derived from a callable `transcribeRecording`; a contradictory explicit declaration is rejected.
Optional `smartTranscription` is boolean when supplied: it declares that
`createSession` honours its optional `mode` option, `"smart"` for cleaned-up
text or `"verbatim"` for text as spoken. Absent `mode` means the provider's
default; providers without the capability ignore it. Optional `label` and
`destination` are nonempty strings naming the service and saying where
microphone audio goes. `streaming` describes streaming recognition,
`interimResults` controls partial display, `keyterms` controls domain-term
building, and `endpointing` distinguishes automatic utterance-end evidence from
manual Done. Capabilities do not confer permissions or confidence/provenance
Expand Down Expand Up @@ -247,6 +253,67 @@ bytes, content type, keyterms and returned text; it is required when this method
is implemented. The [saved-audio tests](../../packages/ui-server/tests/saved-transcription.test.ts)
exercise a fake provider through the real mounted routes without service keys.

## Built-in Gemini 3.5 Transcribe Live dictation

Setting `GEMINI_API_KEY` registers Google's dedicated streaming transcription
model, `gemini-3.5-transcribe-live`, as the built-in `gemini` dictation
provider. `VOICE_PROVIDER=gemini` selects it explicitly. Without
`VOICE_PROVIDER` it is used only when `DEEPGRAM_API_KEY` is unset, so a host
that already has a Gemini key for chat models keeps dictating to Deepgram.
Microphone audio then streams from the browser straight to Google, and the
dictation sheet says so.

The key stays on the server. For each take the server sends one
`POST https://generativelanguage.googleapis.com/v1beta/auth_tokens` with the
key in `x-goog-api-key` and receives a single-use ephemeral token: `uses: 1`,
60 seconds to connect (`newSessionExpireTime`, also the session's
`expiresAt`), 11 minutes overall (`expireTime`). Its `bidiGenerateContentSetup`
carries the model, the `TEXT` response modality and the transcription config,
and its `fieldMask` names exactly those fields, so they are locked and the
token cannot open any other Live session. (`liveConnectConstraints` and
`lockAdditionalFields` are the `@google/genai` option names; the REST body is
what that SDK serializes them to.) The browser's `setup` frame repeats the
locked setup field for field. The transcription config is
`mode: "SMART"` unless `createSession` receives `mode: "verbatim"`, plus the
brain's existing keyterms as `customVocabulary`: at most 100 terms of at most
64 UTF-8 bytes, in order. No chat, history, screen or corpus context is sent.
Language is detected automatically. Every mint failure returns the session
route's 500 `{ "error": "Gemini dictation session failed" }`; neither the key
nor Google's response text appears in a response, log or error, and no other
provider is tried. Capabilities are `streaming`, `interimResults`, `keyterms`
and `smartTranscription`; `endpointing` is false, so the sheet keeps a manual
Done. There is no saved-recording transcription, so `savedAudio` is false.

The session URL is Google's constrained Live endpoint
(`…v1alpha.GenerativeService.BidiGenerateContentConstrained`, the path the
installed `@google/genai` 2.24.0 uses; Google's token guide says `v1beta`, and
[#3710](https://github.com/schlessera/brain-kit/issues/3710) qualifies which
one Google accepts). The browser client `GeminiAsrClient`, registered as
`gemini` by `registerAsrClients`, appends `?access_token=<token>`, sends the
same model and transcription config as its setup, and streams mono PCM16 LE at
16 kHz in 100 ms frames (3,200 bytes) as base64 `realtimeInput.audio`. Its
AudioWorklet captures at the hardware rate and resamples; it never assumes a
16 kHz context. Up to 5 seconds of audio wait for `setupComplete`; more than
that, a 10-second handshake, a socket error or an upload backlog above
256 KiB ends the take with a connection failure rather than dropping audio.
`interimInputTranscription` text replaces the partial; each
`inputTranscription` text is one final (`endsTurn` from `finished`, true when
absent). Done stops the microphone, sends the last partial frame and
`audioStreamEnd`, and waits up to 3 seconds for a `finished` final or
`turnComplete`. A hard stop, cancel or unmount releases the tracks,
AudioContext, worklet, timers, queue and socket. There is no session
resumption: Google ends a session after 10 minutes, and the take then ends as
provider-ended, with the words heard kept for review.

The keyless [server proof](../../packages/ui-server/tests/gemini-speech.test.ts)
runs the published provider conformance and the mounted routes against a
loopback `auth_tokens` double. The [client proof](../../packages/ui-react/tests/asr-gemini.test.ts)
runs the published client conformance and the wire bounds, and the
[Chromium proof](../../packages/ui-react/tests/browser/dictation-gemini.offline.tsx)
dictates through the real ChatPage, worklet and 44.1/48 kHz contexts against
an offline socket. They show protocol and resource behaviour, not that Google
accepts the token or how accurate or fast it is; that is #3710.

## Live conversation with Gemini

Conversation is separate from dictation. Register the fixed Gemini adapter
Expand Down
2 changes: 1 addition & 1 deletion docs/http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ SDK speech-session payloads rather than exposing long-lived provider keys:

| Supported operation | Inputs/defaults | Success | Errors and behavior |
| --- | --- | --- | --- |
| POST `/api/voice/session` | Optional JSON `VoiceSessionRequest` `{ providerId?, smart? }`; absent body uses the effective provider | `VoiceSessionResponse`: providerId, connection url, optional token/params, expiresAt and capabilities (streaming, interimResults, keyterms, endpointing, derived savedAudio) | An explicit unregistered provider gives 409 `speech_provider_unavailable` before minting; malformed/non-object JSON or wrong field types give 400 `voice_session_invalid`. No effective provider or mint/session validation failure gives 500 `{ error }`; no fallback. Keyterms are included only when supported by the provider; browser/local sessions can omit token and use empty URL/zero expiry. |
| POST `/api/voice/session` | Optional JSON `VoiceSessionRequest` `{ providerId?, smart? }`; absent body uses the effective provider | `VoiceSessionResponse`: providerId, connection url, optional token/params, expiresAt and capabilities (streaming, interimResults, keyterms, endpointing, derived savedAudio, optional smartTranscription) | An explicit unregistered provider gives 409 `speech_provider_unavailable` before minting; malformed/non-object JSON or wrong field types give 400 `voice_session_invalid`. No effective provider or mint/session validation failure gives 500 `{ error }`; no fallback. Gemini mint failures are always `{ error: "Gemini dictation session failed" }`, never Google's text. Keyterms are included only when supported by the provider; browser/local sessions can omit token and use empty URL/zero expiry. |
| POST `/api/voice/token` | No inputs | `{ token, expiresAt }` | Deprecated Deepgram-specific alias retained for client migration; mints directly with 60-second requested TTL, 500 `{ error }` on failure. |
| GET `/api/voice/keyterms` | `rebuild=1` forces cache rebuild; all other values read normal cache | `{ keyterms: string[], generatedAt, count }` | 500 `{ error }` on read/build failure, including a missing, corrupt, locked or unreadable index. Without a usable optional `@schlessera/brain` peer, or with an index version core cannot read, 200 with an empty vocabulary that is never cached ([optional core peer](integration-contract/package-api.md#ui-server-optional-core-peer-breaking-host-migration-697)). |
| GET `/api/voice/overrides` | No inputs | `{ overrides: [{ match, replacement }] }` | Configured pronunciation replacements; 500 `{ error }` on cache read/build failure. |
Expand Down
49 changes: 46 additions & 3 deletions docs/integration-contract/package-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1521,9 +1521,9 @@ ids, invalid list entries or an unregistered `defaultSpeechProviderId` fails con
Legacy `speechProvider` replaces all built-ins and must match `VOICE_PROVIDER`.
`defaultSpeechProviderId?: string` sets the host default ahead of `VOICE_PROVIDER`,
then registered Deepgram; a legacy supplied value is its own default. Deepgram
registers when its key is configured; browser speech registers only through
`VOICE_PROVIDER=webspeech`. The Gemini built-in registration point is reserved for
#3708's factory; this change does not advertise a placeholder Gemini implementation.
and Gemini each register when their key is configured (a key adds a choice and
never makes Gemini the host default); browser speech registers only through
`VOICE_PROVIDER=webspeech`.
A saved brain-wide choice overrides the host default. Removed saved choices block
selection; with neither saved nor host choice only a sole provider is selected.

Expand Down Expand Up @@ -1560,6 +1560,49 @@ its protocol-specific authentication, capture and failure behavior. The
[authoring guide](../extending/speech.md) supplies complete public server/client
examples and points to executable harnesses and real route/Chrome integration.

Additive (#3708): `SpeechProvider` gains optional `label?: string` and
`destination?: string`, and `createSession` options gain optional
`mode?: "smart" | "verbatim"`. `SpeechCapabilities` gains optional
`smartTranscription?: boolean`, which declares that the provider honours
`mode`; providers without it ignore the option, and an absent mode means the
provider's default. The server rejects a supplied label or destination that is
not a nonempty string, and a non-boolean `smartTranscription`, with the
existing 500 envelope. The published provider suite checks the same types and,
for a SMART provider, that both modes mint a serializable session. The mounted
session route sends no mode yet, so SMART providers use their default.

The built-in `gemini` provider (`gemini-3.5-transcribe-live`) is selected by
`VOICE_PROVIDER=gemini` and, without `VOICE_PROVIDER`, only when
`GEMINI_API_KEY` is set and `DEEPGRAM_API_KEY` is not. `VOICE_PROVIDER=gemini`
without the key is a selection error. Its capabilities are `streaming`,
`interimResults`, `keyterms` and `smartTranscription` true, `endpointing`
false, and `savedAudio` false. Each session is one
`POST https://generativelanguage.googleapis.com/v1beta/auth_tokens`
(`x-goog-api-key`) minting a single-use token (`uses: 1`, connect within 60 s,
expire after 11 min) whose `bidiGenerateContentSetup` sets
`models/gemini-3.5-transcribe-live`, `generationConfig.responseModalities:
["TEXT"]` and `inputAudioTranscription` (`mode` `SMART` unless `verbatim` is
requested; `customVocabulary` from the keyterms, at most 100 terms of at most
64 UTF-8 bytes, omitted when empty), and whose `fieldMask` locks exactly the
fields set (`model,generationConfig.responseModalities,inputAudioTranscription.mode`,
plus `inputAudioTranscription.customVocabulary` when present). The session is
`{ url: <constrained v1alpha Live endpoint>, token: "auth_tokens/…",
expiresAt: <connect deadline>, params: { model, mode, sampleRate: "16000",
vocabulary: <JSON array> } }`. Any mint failure is 500
`{ error: "Gemini dictation session failed" }` without the key or Google's
text, and no other provider is tried. There is no session resumption: Google's
10-minute session limit ends the take through the client's provider-ended
path. The root-registered `gemini` `AsrClient` appends `access_token`, repeats
the locked setup, and streams mono PCM16 LE at 16 kHz in 100 ms base64
`realtimeInput.audio` frames, resampled from the hardware rate. Its bounds are
5 s of audio before `setupComplete`, a 10 s handshake, a 256 KiB upload
backlog (each failing the take as a network error), and a 3 s wait for the
final after `audioStreamEnd` on Done. Interim text is a replacing partial;
each final transcription is one final, `endsTurn` from `finished` (true when
absent). Keyless proofs establish protocol and resource behaviour, not
Google's acceptance, accuracy or latency
([#3710](https://github.com/schlessera/brain-kit/issues/3710)).

<a id="saved-audio-transcription-additive-1021"></a>

### Saved-audio transcription (additive, #1021)
Expand Down
Loading
Loading