Dictation processing and typing
Dictation processing turns recognized speech into text that fits the user's intent and the app that has focus. It applies spoken commands and number forms, can use optional AI cleanup, records useful feedback, and delivers text or a spoken send action without losing the transcript when delivery is unsafe.
This page is a child of Voice dictation pipeline. Audio and recognition are covered in Audio capture pipeline and Speech recognition engines. Screen and field context are covered in Dictation screen context.
Text processing
Processing flow
The processing flow takes final recognition output through speech formatting, optional cleanup, and delivery. It keeps text insertion separate from the later send action so each result can be checked and reported on its own.
The normal stop path follows this order:
- It receives the final recognition result.
- It applies spoken punctuation.
- It parses a terminal spoken-send command.
- It applies bounded text normalization before any AI cleanup.
- It uses AI only when the active route is configured and allowed.
- It restores protected literal commands, applies app-aware literal formatting, and applies user formatting.
- It delivers the result to the captured destination.
This order keeps the send phrase out of AI input. It also applies user rules after AI output, so cleanup does not undo the user's formatting choices.
The following diagram shows how recognized speech becomes delivered text and how a send request remains a separate action.
flowchart LR
A[Recognized speech] --> B[Spoken punctuation]
B --> C[Spoken-send parsing]
C --> D[Pre-cleanup normalization]
D --> E{AI route valid?}
E -->|Yes| F[AI cleanup]
E -->|No| G[Normalized text]
F --> H[Literal command formatting]
G --> H
H --> I[User formatting and final normalization]
I --> J[History and feedback]
I --> K[Text insertion]
K --> L{Send requested and safe?}
L -->|Yes| M[Send key]
L -->|No| N[Text only or recovery]
References: Sources/…/ContentView.swift• L3264-3385 Sources/…/ContentView.swift• L3415-3465 Sources/…/DictationTextNormalizationService.swift• L4-32
Streaming text
Streaming recognition gives the overlay a live preview before the final stop pass. The preview is useful for feedback, but final delivery repeats the formatting and safety checks before it types or sends text.
References: Sources/…/ASRService.swift• L4754-4835 Sources/…/ContentView.swift• L2519-2634
Dictation formatting
Spoken punctuation
Spoken punctuation turns configured words into marks or layout actions. Context checks keep words that may be normal speech from changing when the intended symbol is not clear.
Supported actions include:
- Punctuation marks and symbols
- A new line or paragraph
- A tab
- A single space
The autoConvertPunctuationEnabled setting controls this stage. When it is off, recognition text passes through without spoken-punctuation conversion.
References: Sources/…/ASRService+SpokenPunctuationFormatting.swift• L3-21 Sources/…/ASRService+SpokenPunctuationFormatting.swift• L126-171 Sources/…/ASRService+SpokenPunctuationFormatting.swift• L214-240 Sources/…/SettingsStore.swift• L4070-4084
Text normalization
Text normalization gives English dictation a shared pass before and after AI cleanup. It converts clear spoken quantity forms to compact text and can convert explicit spoken emoji names when a valid catalog is available. It leaves unsupported languages, empty or unsafe input, protected code, links, and email addresses unchanged.
The normalization service loads the emoji catalog only when the input is within its size limit and contains the word “emoji.” This keeps the common path light while allowing the same formatter snapshot to be reused for later input. A literal escape keeps an explicit spoken emoji name available if AI cleanup would otherwise remove it.
References: Sources/…/DictationTextNormalizationService.swift• L4-32 Sources/…/FluidTextNormalizer.swift• L5-41 Sources/…/DictationQuantityFormatter.swift• L3-24 Sources/…/SpokenEmojiRules.swift• L18-37
Literal formatting
Literal formatting turns spoken forms of slash commands, @ mentions, and related syntax into text that the destination app can use. App and window context limit conversion of ordinary speech. The output also avoids an extra trailing space when the destination app is waiting for its own completion choice.
The literalDictationFormattingEnabled setting controls this behavior. Literal command protection runs around AI cleanup so a cleanup result cannot silently discard an explicit literal request.
References: Sources/…/ASRService+DictationLiteralFormatting.swift• L23-80 Sources/…/ASRService+DictationLiteralFormatting.swift• L153-260 Sources/…/FluidTextNormalizer.swift• L26-40 Sources/…/ContentView.swift• L3364-3385
User formatting
User formatting applies after AI cleanup and literal syntax conversion. It handles final punctuation, first-letter case, and spacing between continuous-dictation segments. When context is needed, the system reads text before the caret so a new segment can continue the sentence already in the destination field.
References: Sources/…/ContentView.swift• L3364-3385 Sources/…/ContentView.swift• L4479-4497 Sources/…/TypingService.swift• L317-320
AI post-processing
Configuration gate
Dictation AI post-processing is optional. The gate selects the effective prompt and provider for the active shortcut and destination app, then allows cleanup only when the provider, model, and required access are valid.
Local routes do not need a remote key. Remote routes do. An off or incomplete route keeps the normalized transcription available for delivery instead of sending an incomplete request.
References: Sources/…/DictationPostProcessingService.swift• L16-91 Sources/…/DictationPostProcessingService.swift• L93-186 Sources/…/DictationPostProcessingService.swift• L201-272 Sources/…/ContentView.swift• L3289-3304
AI refinement
When the gate passes, the system sends normalized text to the selected AI path and returns a refined result. The overlay shows that cleanup is in progress and can show streamed model output. If the request fails, the system delivers the normalized transcription and keeps the failure visible for recovery or retry.
The same boundary applies when a user reprocesses a history item or tests a prompt. The result still receives literal protection and final formatting before it is shown or delivered.
References: Sources/…/ContentView.swift• L3303-3362 Sources/…/ContentView.swift• L3676-3714 Sources/…/ContentView.swift• L4451-4497
Output delivery
Destination focus
The delivery path captures the destination app and focused field before Fluid's interface can take focus. Before insertion or a send key, it checks that the intended process and exact field are still active. It can restore the captured field during recovery, but normal delivery does not move text to an unsafe target.
References: Sources/…/TypingService.swift• L159-218 Sources/…/TypingService.swift• L250-344 Sources/…/ContentView.swift• L4527-4545
Text insertion
Text insertion first tries non-clipboard delivery. If that path does not work, it uses reliable paste. Paste delivery uses temporary clipboard data and restores the prior clipboard unless the user changed it during delivery. A user-enabled backup copy remains separate from this temporary operation.
The delivery coordinator serializes temporary clipboard use so overlapping dictation requests do not replace each other's paste data. Accessibility permission is required for external insertion. If the target is not editable or permission is missing, the transcript can still be copied when backup copying is enabled.
References: Sources/…/TypingService.swift• L474-625 Sources/…/TypingService.swift• L831-916 Sources/…/PasteDeliveryCoordinator.swift• L614-760 Sources/…/SettingsStore.swift• L6188-6210
Clipboard feedback
Paste delivery can check whether text landed in the destination after the paste command. The check is limited to paste paths and records a bounded result even when the baseline or read-back is unavailable. A miss or uncertain result can expose the transcript for recovery when alerts are enabled. User input during the check makes the result unknown instead of claiming that the paste failed.
References: Sources/…/TypingService.swift• L553-623 Sources/…/TypingService.swift• L771-799 Sources/…/SettingsStore.swift• L3646-3653
Send action
A spoken-send request is a follow-up action after text insertion. The system first requires the captured process and exact non-secure field to remain active. It then waits for physical modifiers to be released and checks the same target again before dispatching the configured send key. Text can remain in the destination when a focus change, held modifier, cancellation, or another safety check suppresses the send key.
Text insertion and send dispatch have separate outcomes. The delivery result can distinguish rejection, insertion failure, successful insertion, suppressed action, and dispatched action. When a send key will follow, paste landing verification is skipped because the destination may clear the field immediately after insertion.
References: Sources/…/TypingService.swift• L27-86 Sources/…/TypingService.swift• L628-729 Sources/…/TypingService.swift• L936-966
Spoken send
Send command parsing
Spoken send turns a terminal command phrase into a separate send request. A phrase in the middle of a sentence remains text. A literal escape keeps one occurrence as text while a later terminal occurrence can still request a send.
The parser removes repeated terminal command phrases and cleans the remaining ending. It preserves a final question or exclamation mark. A command by itself sends the existing draft without inserting command text.
References: Sources/…/SpokenSendParser.swift• L3-7 Sources/…/SpokenSendParser.swift• L52-112 Tests/…/SpokenSendTests.swift• L7-61 Tests/…/SpokenSendTests.swift• L213-238
Immediate send
Immediate send can stop recording when the streaming preview finds a terminal send phrase. It waits for a short settle period and requires silence. New voice activity cancels the pending send, which prevents an unfinished phrase from triggering an early action.
References: Sources/…/SpokenSendParser.swift• L8-50 Sources/…/ContentView.swift• L2519-2585 Sources/…/ContentView.swift• L2598-2634 Tests/…/SpokenSendTests.swift• L90-211
Feedback
History review
Dictation history lets the user compare raw recognition text with the processed result. It also records the destination and AI outcome so a result can be understood after delivery.
The history view supports search, pinned entries, copying, raw-versus-processed review, and visible AI failure state. Load and save errors remain visible so missing history is not mistaken for an empty history.
References: Sources/…/TranscriptionHistoryStore.swift• L23-45 Sources/…/TranscriptionHistoryStore.swift• L441-459 Sources/…/TranscriptionHistoryStore.swift• L614-685 Sources/…/TranscriptionHistoryView.swift• L65-116 Sources/…/TranscriptionHistoryView.swift• L278-459
Transcription reports
A history entry can be sent as an anonymous model example. The user can review and edit the raw text, processed text, model, and optional comment before sending. Network or server errors stay in the form so the user can retry.
References: Sources/…/TranscriptionHistoryView.swift• L648-675 Sources/…/TranscriptionHistoryView.swift• L779-879 Sources/…/TranscriptionFeedbackReporter.swift• L3-47
Change checklist
When these files or sections are changed, remember to consider these:
- Keep pre-cleanup and post-cleanup normalization aligned so AI cannot undo quantity or spoken-emoji output.
- Keep literal command protection aligned with the AI boundary. An explicit literal request must not disappear during cleanup.
- Keep spoken-send parsing aligned with both the streaming immediate-send check and the final post-insertion action.
- Keep captured focus checks aligned with send-key checks. A matching app is not enough when the exact field changed or is secure.
- Keep direct insertion, paste fallback, temporary clipboard ownership, and clipboard restoration aligned. Changes can lose text or overwrite a later user copy.
- Keep paste verification and recovery evidence aligned with alert behavior. A late result must not offer stale text or hide an uncertain paste.
- Keep separate insertion and send outcomes aligned with overlay feedback. Inserted text must remain visible when the send action is suppressed.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The normalization catalog is missing or invalid | Spoken emoji stays as words | The base formatter remains valid and only uses the catalog after validation |
| AI refinement fails | The refined result is unavailable | Normalized transcription remains the delivery fallback and the error stays visible |
| Accessibility permission is missing | External insertion fails | The service reports a recoverable failure and can copy a backup transcript |
| No editable destination is focused | Text is not inserted into another app | Target assessment rejects a clearly non-editable field |
| Direct insertion is rejected | The first delivery path fails | The service falls back to reliable paste |
| User changes the clipboard during paste | A later user copy could be overwritten | Clipboard ownership and change checks protect newer clipboard data |
| Paste read-back times out or has no baseline | The system cannot confirm that text landed | Bounded verification records an uncertain result and can expose transcript recovery |
| Exact focus changes before send | Text may be inserted but the send key is suppressed | The process, field, secure-field state, and modifier state are checked again |
| The send target is secure or fails the pre-insertion focus check | The send path is suppressed and the transcript uses the recovery copy | The preflight requires the captured non-secure field and matching target process |
| User speaks during immediate-send settling | The pending send is cancelled | Voice activity cancels the countdown |
Key files
| File | Why to read it |
|---|---|
| Sources/…/ContentView.swift | Connects final recognition, normalization, AI gating, delivery, reprocessing, and spoken send. |
| Sources/…/ASRService.swift | Provides streaming preview and final text formatting context. |
| Sources/…/ASRService+SpokenPunctuationFormatting.swift | Defines spoken punctuation conversion and context rules. |
| Sources/…/ASRService+DictationLiteralFormatting.swift | Defines literal command and mention output. |
| Sources/…/DictationTextNormalizationService.swift | Selects and caches the optional spoken-emoji normalizer for eligible input. |
| Sources/…/FluidTextNormalizer.swift | Defines the shared before-cleanup and after-cleanup normalization boundary. |
| Sources/…/DictationQuantityFormatter.swift | Defines spoken quantity conversion and protected text behavior. |
| Sources/…/SpokenEmojiRules.swift | Defines valid spoken-emoji names and literal escapes. |
| Sources/…/DictationPostProcessingService.swift | Defines optional AI route checks and refinement. |
| Sources/…/TypingService.swift | Captures focus, delivers text, verifies paste landing, and reports insertion and follow-up action outcomes. |
| Sources/…/PasteDeliveryCoordinator.swift | Owns temporary clipboard use, paste delivery, backup copies, and restoration. |
| Sources/…/SpokenSendParser.swift | Parses terminal send commands and immediate-send timing. |
| Sources/…/TranscriptionHistoryStore.swift | Stores raw and processed text with delivery context and AI outcome. |
| Sources/…/TranscriptionHistoryView.swift | Provides history review and transcription feedback actions. |
| Sources/…/SettingsStore.swift | Defines text insertion, formatting, clipboard, and feedback-related settings. |