Open History to see the last commit
1# Voice input
2
3> For maintainers. Using T3 Code? See [voice input on iPhone](../user/composer.md#voice-input-on-iphone).
4
5Voice input produces editable composer text. The current implementation records on the client and
6transcribes locally with Apple's `SpeechAnalyzer` and `SpeechTranscriber` on supported iOS 26+
7devices. Environment-provided transcription and transcription on web and desktop are not implemented.
8
9## Current boundaries
10
11The shared [`VoiceInputController`][controller] in `packages/client-runtime` owns preparation,
12recording, transcription, cancellation, temporary-file cleanup, and insertion into the captured
13draft selection. Applications import it through the [voice-input entry point][voice-input] as
14`@t3tools/client-runtime/voice-input`. Its dependencies separate capture from transcription; the
15controller imports neither React Native nor an Apple transcription API.
16
17The shared [transcription contract][transcription] defines `VoiceTranscriber`,
18`PreparedVoiceTranscription`, and transcription errors. The controller calls `getTranscriber()` once
19at the start of an operation, before asking for microphone permission. Preparation returns a resolved
20locale and a bound `transcribe` function. The controller retains that result for the recording, so a
21selection change cannot prepare with one implementation and transcribe with another.
22
23[`useVoiceInputController`][hook] supplies Expo audio capture, microphone permissions, audio-session
24management, waveform samples, and app and navigation lifecycle handling. It normalizes Expo's
25`mediaServicesDidReset` into a generic recorder error. [`voiceTranscription.ios.ts`][ios] adapts
26`@react-native-ai/apple` through `getLocalVoiceTranscriber()`, capturing the requested device locale
27and binding the prepared transcriber to Apple's resolved locale. The other-platform binding returns
28no local transcriber. That result describes the local implementation, not whether a client could use
29an environment's transcription service.
30
31Mobile's [`voiceInputPresentation.ts`][presentation] maps shared state to toolbar labels and actions.
32Waveform and toolbar rendering stay in mobile. The composer edits draft text without selecting a
33speech vendor.
34Recording captures the draft owner, revision, text, and selection. A late transcript cannot overwrite
35a different or edited draft. Only normal message submission sends the resulting text to an agent.
36
37Each operation passes one `AbortSignal` through preparation and transcription. Cancellation
38invalidates the operation and aborts that signal immediately. Implementations settle their promises
39only after their underlying work stops. The Apple binding checks cancellation between asynchronous
40steps but cannot interrupt an in-flight native request. The controller retains its session until
41that work settles, ignores its result, and cleans up the recording.
42
43## Ownership decisions
44
45The extension boundary distinguishes transcription on the client device from transcription through
46the composer's environment. These constraints apply when adding selectable transcription services:
47
48- Local means the client device, regardless of which machine hosts the environment. A device's lack
49 of local recognition does not prevent it from recording audio for an environment service.
50- Remote service configuration and API keys belong to the environment. The environment calls the
51 external service. Clients receive service identifiers, labels, and availability information, never
52 credential values. Transcription services are independent of coding-agent `providerInstances`;
53 selecting OpenAI for transcription does not select Codex for the thread.
54- The client owns its transcription preference, scoped by stable `environmentId`. Its choices are
55 supported local recognition and the services exposed by the composer's environment. A service ID
56 is meaningful only within that environment. Different clients can make different choices.
57- Resolve and capture the environment, selected service, and locale when an operation starts.
58 Preparation and transcription use the same selection; preference changes affect the next
59 recording. Capture environment identity explicitly rather than recovering it from a draft key.
60 Keep the existing draft-owner and revision checks before inserting text.
61- If the selected option is unavailable, report that state and let the user choose another option.
62 A local failure must not silently upload audio, and a disconnected environment must not redirect
63 a recording to another environment or service.
64- Transcription audio is temporary input, separate from durable chat attachments and messages.
65 Remote adapters need cancellation of upload and transcription where supported, cleanup after
66 success, failure, or cancellation, and the same protection against late results as local transcription.
67
68## Existing integration points
69
70[`ServerSettingsService`][settings] and [`ServerSecretStore`][secrets] provide environment-owned
71configuration and secret persistence. Existing settings redaction handles coding-provider environment
72variables only. Any transcription credential fields need their own explicit separation and redaction
73before settings responses or subscriptions reach client caches.
74
75[`ExecutionEnvironmentCapabilities`][capabilities] handles version skew. Remote transcription must be
76opt-in: a missing transcription capability means unsupported. The authenticated server-config
77subscription and [shared environment state][server-state] already distribute configuration per
78environment. A transcription service catalog belongs behind that capability and authenticated
79boundary. Older servers expose no remote transcription choices.
80
81The [attachment upload contracts][uploads] and [shared upload operations][attachment-state] provide a
82pattern for authorized binary uploads through an environment, including remote connections. Their
83existing chat-attachment retention is not a transcription cleanup policy.
84
85Future service selection and environment requests belong alongside the controller in
86`packages/client-runtime`, with wire contracts in `packages/contracts`. Capture and native local
87recognition remain client-specific. An environment-backed transcriber implements the same shared
88contract, with its environment and service bound when selected. The controller does not own service
89credentials, provider SDKs, or transport selection.
90
91[controller]: ../../packages/client-runtime/src/voice-input/controller.ts
92[voice-input]: ../../packages/client-runtime/src/voice-input/index.ts
93[transcription]: ../../packages/client-runtime/src/voice-input/transcription.ts
94[hook]: ../../apps/mobile/src/features/voice-input/useVoiceInputController.ts
95[presentation]: ../../apps/mobile/src/features/voice-input/voiceInputPresentation.ts
96[ios]: ../../apps/mobile/src/native/voiceTranscription.ios.ts
97[settings]: ../../apps/server/src/serverSettings.ts
98[secrets]: ../../apps/server/src/auth/ServerSecretStore.ts
99[capabilities]: ../../packages/contracts/src/environment.ts
100[server-state]: ../../packages/client-runtime/src/state/server.ts
101[uploads]: ../../packages/contracts/src/assets.ts
102[attachment-state]: ../../packages/client-runtime/src/state/attachments.ts