Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/gemini-dictation-drain-language.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@schlessera/brain-ui-react": patch
"@schlessera/brain-ui-server": patch
---

Gemini dictation finishes Done faster and recognizes English with a fixed language hint. Google never sends `finished` or `turnComplete` after `audioStreamEnd`, so Done waited its full 3 s every time. Done now ends as soon as Google's answer reaches the end of the stream, and otherwise after 300 ms of quiet. Voice the microphone heard that Google has not yet signalled holds Done in a 1.5 s window, so words spoken just before Done are less likely to be cut off. The 3 s cap still bounds every wait (#3768). The minted token now locks a fixed English recognition hint, `languageCodes: ["en-US"]`, and the client repeats it, matching Deepgram's fixed `en`. With automatic detection, a short English segment had come back as Spanish (#3769).
98 changes: 74 additions & 24 deletions docs/plans/selectable-dictation.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,45 @@ dependency: both sides speak the documented wire protocol, as
| A browser presents the token as an `access_token` query parameter (or `Authorization: Token …`); tokens work only with the Live API | Token guide |
| `gemini-3.5-transcribe` (unary, saved files) is a separate model and endpoint | Model page |

**Divergence to resolve during qualification.** The token guide says ephemeral
**Endpoint version (resolved by #3710).** The token guide says ephemeral
tokens work with `v1beta`. The installed SDK connects an `auth_tokens/…`
credential to
`wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1alpha.GenerativeService.BidiGenerateContentConstrained?access_token=…`
and warns that its ephemeral support is v1alpha-only. The implementation uses
the SDK-observed v1alpha `BidiGenerateContentConstrained` URL. The server mints
the full URL, so a correction is a server-only change. #3710 records which one
Google accepts.

**Still unproven until #3710 runs:** that Google accepts the constrained token
and setup for this model; whether interim text is cumulative per segment or
per message; whether every final text is followed by `finished`, or by
`turnComplete`, after `audioStreamEnd`; the actual SMART output for corrections
and lists; latency; and physical-device behavior. No keyless test proves any of
these. Nothing here claims parity with Pixel Recorder or Rambler features, or
and warns that its ephemeral support is v1alpha-only. Measured on 2026-11-09,
Google accepts the constrained token on both the v1alpha and the v1beta
constrained endpoints, with identical output. The implementation keeps the
SDK's v1alpha URL. The server mints the full URL, so a later change is
server-only.

**Measured by #3710's scripted check of the protocol (2026-11-09,
synthetic TTS audio, no device):**

- Google accepts the constrained token and setup for this model.
- `uses: 1` is enforced: a second connect closes with 1011 "Token has been used
too many times".
- The locked mode overrides a client `setup` that asks for another one.
- Interim text is cumulative within a segment and stays verbatim in SMART;
only the final is cleaned.
- A final arrives on a pause, as `inputTranscription`, then
`generationComplete: true`, then `speechState: NON_SPEECH` with a top-level
`voiceActivity: { type: "ACTIVITY_END", audioOffset }`. Speech starts with
`speechState: SPEECH` and `ACTIVITY_START`, about 75 ms after the audio
reached Google. `audioOffset` counts from the first audio of the stream;
`ACTIVITY_END` fell 0.7–1.3 s after the last voiced audio, or at the stream
end when speech ran into it.
- After `audioStreamEnd`, Google sends the pending final and `generationComplete`
(+253 ms measured). When nothing is pending it sends nothing at all.
`finished` and `turnComplete` never came, so Done ends on Google's answer
rather than on those flags (#3768).
- A pause ends a segment, so SMART formats a spoken list only within one
segment.
- With automatic language detection, a short English segment was once
returned as Spanish. The `en-US` hint fixed it in the one session tried
(#3769).

**Still unproven until #3710 Phase B runs:** latency and behavior with a real
microphone, a real browser and a physical device. No keyless test proves any
of these, and none of the measurements above is an accuracy claim. Nothing here claims parity with Pixel Recorder or Rambler features, or
that saved files work because streaming does.

## 3. Rulings this design uses
Expand Down Expand Up @@ -308,8 +332,9 @@ x-goog-api-key: <server key>
"model": "models/gemini-3.5-transcribe-live",
"generationConfig": { "responseModalities": ["TEXT"] },
"inputAudioTranscription": { "mode": "SMART",
"languageCodes": ["en-US"],
"customVocabulary": ["Ithaca", "Penelope", "…"] } },
"fieldMask": "model,generationConfig.responseModalities,inputAudioTranscription.mode,inputAudioTranscription.customVocabulary" }
"fieldMask": "model,generationConfig.responseModalities,inputAudioTranscription.mode,inputAudioTranscription.languageCodes,inputAudioTranscription.customVocabulary" }
```

This is the REST AuthToken that `@google/genai` 2.24.0 serializes from
Expand All @@ -323,18 +348,23 @@ x-goog-api-key: <server key>
{ "url": "wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1alpha.GenerativeService.BidiGenerateContentConstrained",
"token": "auth_tokens/…", "expiresAt": 1783847400000,
"params": { "model": "models/gemini-3.5-transcribe-live", "mode": "SMART",
"sampleRate": "16000", "vocabulary": "[\"Ithaca\",\"Penelope\"]" } }
"sampleRate": "16000", "vocabulary": "[\"Ithaca\",\"Penelope\"]",
"languageCodes": "[\"en-US\"]" } }
```

- Vocabulary is the existing bounded keyterm list, capped at **100 terms** of at
most 64 UTF-8 bytes each. No corpus, history, screen or chat context is sent.
Language uses automatic detection (`languageCodes` omitted). Adding a
language setting is out of scope for this epic; Deepgram stays `en`.
Language is a fixed `languageCodes: ["en-US"]` hint, locked in the token and
repeated in the setup, matching Deepgram's fixed `en` (#3769: automatic
detection returned a short English segment as Spanish). A hint biases
recognition; it does not restrict it. Adding a language setting is out of
scope for this epic.
- The constraint locks model, modality and transcription config, and the
browser's `setup` repeats them field for field. Any additional field the
client sends is rejected or overridden by Google, which is the point of the
lock. Whether Google enforces the `fieldMask` this way, and which API version
(`v1alpha` or `v1beta`) accepts the token, is a #3710 check.
lock. #3710 measured it: a client setup asking for another mode or model
still got the locked transcription, and both `v1alpha` and `v1beta` accept
the token.
- Token TTL: one use, 60 s to connect, 11 minutes overall (the 10-minute
session plus margin). **No session resumption** in the first delivery: a take
ends at Google's 10-minute limit through provider-ended, and its words go to
Expand Down Expand Up @@ -368,10 +398,28 @@ x-goog-api-key: <server key>
Messages are zod-parsed with the same size bounds as `gemini-conversation.ts`.
`error`, `goAway` and unknown-close reasons map to `speechError` codes
without exposing their text.
- **Done (`drainAndStop`).** Stop the tracks, flush the partial chunk, send
`audioStreamEnd`, then wait for the next `inputTranscription` with
`finished`, or `turnComplete`, for up to **3 s**. Close either way. Words
already heard are kept.
- **Done (`drainAndStop`).** Stop the tracks, flush the partial chunk and send
`audioStreamEnd`. Then, at the stream end and after every later message
about speech (an interim, a final, `speechState`, `generationComplete`,
`turnComplete` or `voiceActivity`; any other message is ignored):
- While a segment is open (a `SPEECH` state or an interim that no final,
`generationComplete`, `finished` or `turnComplete` has closed), wait.
- While the microphone heard voice (block RMS ≥ 0.015) more than one frame
past Google's last `ACTIVITY_END` offset, wait a **1.5 s** tail window:
Google has not yet signalled that speech, and an earlier segment's answer
may still be arriving. Later messages do not restart a running window; if
Google never calls the voice speech, Done ends when it lapses.
- When a message's `ACTIVITY_END` reaches the stream end (within one frame,
since Google reports 10 ms steps), Done ends at once.
- Otherwise wait **300 ms** of quiet, restarted by each such message. This
covers the stream end with nothing pending, and an earlier segment's
answer that stops short of the stream end, where speech too quiet for the
RMS bar may still be signalled.

A lapsed window first processes messages that already arrived, so a final
still decoding is kept, and one that reopened a segment wins. The RMS bar
is a heuristic: speech it misses gets only the 300 ms window. **3 s** caps
all of it (#3768). Close either way. Words already heard are kept.
- **Hard stop, cancel, unmount, superseded start.** Close the socket (1000),
disconnect the worklet, close the AudioContext, stop the tracks, clear the
timers and the queue, and ignore every later message, because the existing
Expand Down Expand Up @@ -502,8 +550,10 @@ key-registered built-in over the legacy single selection.
- Client: published `runAsrClientContract`, plus a local WebSocket double that
asserts the setup frame, base64 PCM16 framing at 16 kHz from 44.1 and 48 kHz
contexts in real Chrome, the pre-setup buffer bound, backpressure failure,
interim replacement, single final commit, the `audioStreamEnd` drain within
3 s, and complete teardown (tracks ended, context closed, socket closed, no
interim replacement, single final commit, the `audioStreamEnd` drain (on
`generationComplete` and `ACTIVITY_END`, waiting for voice Google has not
signalled and for messages still decoding, after a quiet with nothing
pending, capped at 3 s), and complete teardown (tracks ended, context closed, socket closed, no
late mutation).
- Mutations: final mapped as partial, resampler bypassed, constraint lock
removed, teardown skipping `context.close()`. Each fails its named
Expand Down
Loading
Loading