Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

voice-input.md

66 lines4.0 KB

1# Voice input
2​
3Transcription edits a composer draft. It does not submit an agent turn. Audio is
4temporary client input, and only normal message submission sends the resulting
5text. Mobile defaults to on-device transcription; any client that sends audio off
6the device needs a grant for one environment.
7​
8The [shared controller](../../packages/client-runtime/src/voice-input/controller.ts)
9owns the operation while the client supplies capture and transcription. Preparation
10binds the transcriber and resolved locale for the whole recording. Draft ownership,
11text, and revision are captured before recording and checked before insertion, so
12a late transcript cannot overwrite a draft that was edited or replaced. A
13transcriber may expose a streaming session, in which case audio leaves during
14capture and `finish` replaces the file-based `transcribe`.
15​
16## Where audio may go
17​
18Only an explicit audio grant authorizes off-device transcription. On mobile the
19grant is stored in device-bound secure storage, outside preference backups. The
20recorder is the same for both destinations; only a finished recording can be
21uploaded, and its grant is checked again after native decoding and before dispatch.
22The [web grant](../../apps/web/src/speech/voiceConsent.ts) lives outside the preferences snapshot so another
23window saving unrelated settings cannot resurrect a revoked grant. Each new
24choice gets a distinct grant, even if the destination was previously selected. The
25[web hook](../../apps/web/src/speech/useEnvironmentSpeechInput.ts) binds a
26recording controller to the prepared connection of that destination and to
27nothing else. When the destination changes, disconnects, or stops advertising the
28`voiceTranscription` capability, the controller is disposed: a recording in
29progress is discarded, a failed recording kept for retry is deleted, and nothing
30falls back to another environment. Every sender in the web app, including the
31settings page's transcription test, goes through that hook. The microphone loopback
32test captures separately for local playback and sends nothing. The transport
33refuses redirects so credentials and audio cannot follow one to another host.
34​
35Transcript cleanup requires its own grant, off by default.
36It sends text, never audio, to the text generation provider of the draft's
37own environment, because that is where the provider credentials live. A later
38backend adds its own destination kind, disclosure, and transcriber; capture and
39the controller stay as they are.
40​
41## Server side
42​
43The [speech service](../../apps/server/src/speech/SpeechService.ts) runs
44transcribe-cpp in a child process so a hung native call can be killed without
45taking the server down; see [native.ts](../../apps/server/src/speech/native.ts)
46for the packaging constraints (Node SEA, Electron ASAR). One native request runs
47at a time. Batch uploads carry their options in the body framing defined in
48[shared/speech.ts](../../packages/shared/src/speech.ts); streaming sends them in
49the socket's first command. Model files and the selected model, hardware
50placement, and unload timeout are environment state in server settings.
51​
52The Silero silence detector is optional. If its download fails, recordings use
53raw audio during the retry cooldown so a detector outage cannot block dictation.
54Explicitly installing a speech model also retries the detector without waiting.
55​
56## Cancellation and resource ownership
57​
58Cancellation invalidates a result immediately, but resources stay owned until the
59underlying work settles. Apple's native transcription call cannot be interrupted
60once started. Releasing the session or deleting its recording when the abort signal
61fires would race that work. The [transcription contract](../../packages/client-runtime/src/voice-input/transcription.ts)
62therefore requires implementations to settle only after their work has stopped;
63the [Apple binding](../../apps/mobile/src/native/voiceTranscription.ios.ts) checks
64cancellation between native calls and discards late results. On the server,
65interrupting a batch request kills the worker process instead; the next request
66reloads the model.