docs/native-voice.md
Native voice input and local Read aloud
Voice input
The app-owned microphone sits on the right of the composer beside Send. Tap
to start talking with the explicitly chosen speech-to-text app. Hold the mic
or choose Input → Voice settings to open the same full-screen native
configuration Activity. First use opens this screen rather than recording, even
if only one app is installed. The screen uses PreferenceFragmentCompat with
three ordinary AndroidX preference rows below a toolbar Back arrow:
- Speech-to-text app: a
ListPreferenceshows the selected application label (for example FUTO Voice Input), not a generic activity label. Tapping opens the standard single-choice preference dialog; Cancel leaves the choice unchanged. Duplicate labels include exact package/activity names. The explicit component is remembered; there is no default provider, hardcoded preferred app or automatic first choice. Options refresh on resume and before opening the dialog, and the selected entry is revalidated before saving, including restored/stale dialogs. - Auto-send voice input: a
SwitchPreferenceCompat, persisted immediately, default on. The summary is On sends recognized text or Off allows review. Off leaves the recognized text in the draft for ordinary Send. - Text-to-speech: an ordinary
Preferenceshows the configured system engine app label when known, or System default. Tapping opens Android TTS settings.
All three preferences are nonpersistent AndroidX widgets; changes route through
only the existing VoiceInputSettings backing store and configuration revision.
There is no additional preference store, Done action or recording continuation.
Changes save immediately. Back returns to chat and never starts dictation
or sends; tap the mic when ready. Opening settings abandons any earlier pending
dictation authority (including already-returned text waiting for chat to resume),
while keeping its outstanding external result route as a discard sink until it
returns. Back cannot apply that earlier result, even if no preference changed.
Merely opening settings captures no composer, request or send continuation and
performs no RPC. The Input menu path stays available in disconnected chat too.
The Text-to-speech row uses the configured Android TTS engine's app label
only when the secure default setting and matching visible service metadata are
readable. Otherwise it says System default, never guesses from the first
installed engine. This is configuration metadata, not a connection guarantee:
Android may fall back to another engine at runtime. The label refreshes on resume,
including return from system TTS settings. Displaying it never initializes or
synthesizes TTS. There is no per-app engine/voice/language override or installer.
Dictation remains independent of Android's reading configuration.
Provider-unavailable/no-app summaries remain contextual; when no apps are
available, the provider row is disabled without disabling Auto-send.
If the saved component is absent, disabled, unexported or no longer handles
android.speech.action.RECOGNIZE_SPEECH, a tap opens settings with guidance, never
silently chooses another app. No speech-to-text app is installed automatically.
The auto-send setting remains accessible when no app is available.
The recognizer owns audio capture and its own permissions/privacy policy;
EzAgent neither requests RECORD_AUDIO nor binds SpeechRecognizer or a
RecognitionService. A dummy service does not prevent a compatible recognizer
activity from being used.
Only a configured direct mic tap, after provider revalidation, captures the exact
workspace selection visit/connection, RAM composer origin/revision/text/selection,
attachment origin/intake token and auto-send choice. Final nonempty EXTRA_RESULTS text replaces that
captured selection (or inserts at its cursor), preserving the remaining draft.
It appears in the composer before submission. With auto-send off it remains for
review and ordinary Send. Transcription is literal chat input, even when it begins
with /help, a mode or a macro name. That RAM-only literal marker survives
Activity recreation, navigation back to the origin and nonempty manual edits;
clearing the composer or a command-owned programmatic replacement resets it.
It is not a new wire format or server command escape.
Auto-send uses the existing reservation, fresh head/parent checks, prompt vs steer, image snapshot, acknowledgement and uncertainty pipeline. It does not bypass authority, clear drafts early or automatically retry an unknown send. No change to slash commands for ordinary typed input. Existing selected images are included normally and clear only on acknowledgement of their exact snapshot.
Cancel, non-OK result, absent/blank/malformed/oversize text never send. Final results are bounded to 16,384 characters, not silently truncated. Each launch has a distinct Activity Result API key; application authority is consumed before any edit/send, so old or duplicate callbacks cannot complete a new launch. The callback stays attached even while stopped; registry cleanup runs after result dispatch, independently of application delivery. A pre-save hook flushes completed cleanup before AndroidX snapshots its registry, removing completed keys and duplicate raw results rather than retaining speech Intents in saved state. Valid text waits in RAM for RESUMED and rechecks connection/selection visit, composer revision and image intake token. Changing either voice setting invalidates an earlier pending result (including changing it back); turning auto-send off cannot leave an old auto-send continuation active, and changing provider never retargets an old result. Opening settings without changing anything grants no new authority. Navigation (including A/B/A), reconnect, edits (even undo), image intake/removal and pending/unknown work invalidate stale results. No delayed transcript overwrites intervening text or targets a different session.
There is one total outstanding route, live or abandoned. Only its opaque key is saved. After Activity/process recreation, a discard-only callback is attached in onCreate before framework delivery. It drains a returning success/cancel without reading its extras, restoring a Request, relaunching recognition or sending text. Normal returned/canceled requests reclaim the slot, and a new recording can begin. No transcript, composer identity or send continuation is saved. Already accepted review text remains separate process-RAM workspace state.
Availability limit: if a recognizer never returns, or an older snapshot is restored after its operation already completed, the one slot can remain blocked in that Activity record. Rotation is not cancellation. The microphone explains that the prior recognizer must return/cancel; finishing the old chat screen and opening a genuinely new Activity record creates a fresh registry. Restoring the old record is not a reset. No timeout silently drops the route or admits a growing list of abandoned UUIDs. A registration-time pending-result replay is drained but is not proof that AndroidX retired its launch marker; this uncertain case also stays bounded/fail-closed until an actual dispatch can retire it. There are no private-registry edits, compatibility readers or restored speech/send authority.
Read aloud
Assistant prose row overflow and heading long-press menus offer Read aloud. While a local reading is pending or speaking, the same menus also offer Stop reading. Starting another reading stops the previous one. This is a local presentation action: historical, provisional and read-only prose does not need canonical idle-tip mutation eligibility. Tools, thinking, users, attachment metadata and error/system rows do not offer it. Empty assistant placeholders also do not offer Read aloud; it becomes available on the actual answer/prose row.
The immutable rendered Markdown document supplies readable headings, paragraphs, list/quote text, link labels and table cells. Fenced/indented code is skipped; inline code is readable text. Link destinations and tool/thinking envelopes are not spoken. Cell/block trailing whitespace is normalized before joining with fixed row/block separators, so appending prose after a table does not change already queued speech. Existing literal rendering fallbacks remain literal. Exact Copy source, selectable spans, renderer anchors and canonical turn actions are unchanged. Explicitly selecting a streaming prose row follows that exact turn/row only, in its original workspace origin and selection visit. It never switches to the newest assistant or automatically reads another reply. Historical prose still reads once. A nonstreaming canonical body with no per-turn recovery pending releases its remaining tail; message-end alone or a temporarily absent row does not fabricate final completion. Per-turn hydration is sufficient; local reading does not wait for unrelated full-cut/tip mutation authority. Historical and validated provisional nonstreaming bodies remain locally readable.
Streaming speech deliberately lags the current unfinished Markdown paragraph: only blank-line-terminated source is eligible, with the final tail released on completion. It reparses that source prefix and validates it against the full rendered readable text. Opening/closing emphasis and inline links within the uncommitted paragraph cannot speak provisional markup then replay its replacement. This also means a single long paragraph may wait until completion, rather than reading token by token. At current-end, the read remains selected and waits for a renderer delivery; no worker/timer/poll loop runs. Growth before TTS init, during the sole in-flight utterance, or while waiting extends the same read without flushing/replaying queued speech. Completion while behind drains in order.
Raw-source nonappend rewrites, changed known sequence identity, gaps/conflicts,
a selected answer becoming an error, or a normalized rewrite affecting the already
queued/spoken prefix stop reading
with a visible notice rather than guessing/replaying. A present same-turn canonical
non-assistant entry (including kind error) also retires the selected read, even
if its presentation row key changes; this is scoped to the exact origin/visit/turn,
not generic row absence, and its replacement content is never narrated.
Append-only Markdown can
still reinterpret earlier reference links; that genuine rewrite follows the same
stop policy. Unqueued text can be reparsed. Paging or temporarily missing rows
cannot select a replacement or release an unverified tail; reappearance can only
extend the same identity under the same prefix checks. Stop, scope changes,
disconnect, renderer detachment, backgrounding, recreation and synthesis errors
retire authority; later deliveries/callbacks cannot resume automatically.
android.speech.tts.TextToSpeech uses the system-default engine, language and
voice without overriding them. Network/offline behavior belongs to the selected
system engine/voice: both are allowed. Null voice/language metadata is unknown,
not evidence that synthesis will fail. No models, engine installer or cloud client
are bundled. Actual initialization, synchronous speak and utterance failures offer
an actionable notice with Text-to-speech settings; there is no metadata-only
rejection or implicit language/engine substitution. The app never starts an engine
install/download. If the settings activity is absent, the notice gives manual
Settings guidance. Correct the system configuration, then explicitly try again.
One bounded response (maximum 200,000 characters) and one platform-sized chunk are retained; only one chunk is queued at a time. Chunk boundaries preserve UTF-16 surrogate pairs and prefer natural breaks. There is no app TTS worker pool or unbounded prequeued utterance list. Engine/init and utterance IDs scope async callbacks; duplicate completions and canceled initialization failures cannot advance or interrupt another reading or open notices in a new scope. Session/ connection navigation stops reading; Activity stop releases/shuts down the engine, and destruction closes it. Returning never resumes reading automatically.
Validation boundary
Permanent offline regressions cover external activity results, API 26 and 35, persistent preference, canceled/stale/duplicate callbacks, literal slash text, composer selection/edit/recreation, session/scope changes, send/steer/images and unknown sends; renderer eligibility and local menus; TTS initialization, replacement, cancellation, errors, long-response chunking and safe Unicode cuts. Actual renderer-to-controller tests use a controllable TTS engine for live growth, current-end wait, completion while behind, Markdown boundaries/reference rewrites, duplicate/stale deliveries, exact identity and stop/lifecycle retirement. Settings tests cover concise controls, configured app-label refresh, system-settings Intent, unknown/restricted default reads without engine construction, and API 26/35. Registry save/recreation tests inspect completed mappings, pending Intents and key-only metadata, including a pending-replay uncertainty fixture and one-slot never-returning-provider limits. Production ChatActivity configuration/direct-tap result tests use a fake transport for auto/review and abandoned/canceled/stale/ duplicate returns. Local settings tests cover first use, explicit app labels, duplicate-label disambiguation, enabled/exported activity filtering, unavailable saved providers, no implicit choice, persistence/default-on/off, Back and recreation without recording. AndroidX settings tests exercise displayed native rows and the single-choice dialog, Cancel, immediate switch summaries/persistence, and provider removal/disable after a dialog snapshot, including recreation. Native Input menu and consumed mic long-press tests check the non-recording configuration path. Pending settings/provider changes cannot acquire new send authority. Platform-adapter regressions admit network-required default voices and null voice/language metadata without overrides or configuration-only rejection. These do not establish real microphone accuracy, FUTO/device behavior, audibility, engine installation, TalkBack or phone acceptance. Coordinator-owned device setup, installation and integration validation remain separate.