feat: smart trailing punctuation for non-prose dictations#110
Open
karansinghgit wants to merge 1 commit into
Open
feat: smart trailing punctuation for non-prose dictations#110karansinghgit wants to merge 1 commit into
karansinghgit wants to merge 1 commit into
Conversation
Speech models punctuate everything as a sentence, so dictating an email, URL, number, or single word ends with a stray period that breaks pasting into address/login/number fields. Add a deterministic post-processing pass that strips a lone trailing period when the entire transcript is one of those shapes. Runs after dictionary replacements so spoken snippets that expand to an address benefit too. Multi-word dictation, ellipses, ?/!, and dotted abbreviations (U.S.) are never touched. Gated by a default-on "Smart trailing punctuation" toggle in Settings -> General -> Transcript Cleanup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Speech models punctuate everything as prose. Dictate an email, URL, number, or a single word and the transcript arrives as
roy@example.com./example.com/pricing./3.14.— the sentence-final period breaks pasting into address bars, login fields, and number inputs.Fix
A deterministic post-processing pass (
SmartTrailingPunctuation) that strips a lone trailing period when the entire transcript is one of these shapes:roy@example.com.→roy@example.comwww., or bare domain with a plausible TLD (final label ≥ 2 letters, soU.S.is not treated as a domain)Hello.→Hello(tokens with internal dots must qualify as email/URL/number, so dotted abbreviations keep their period)Never touched: multi-word dictation (even one ending in an email), ellipses (
.../…),?!, andU.S.-style abbreviations.It runs in
TranscriptionManager.transcribeafterDictionaryService, so spoken snippets that expand to an address benefit too, and it applies uniformly to both engines (Whisper, Parakeet).Toggle
Default-on “Smart trailing punctuation” toggle in Settings → General → Transcript Cleanup (absent key counts as enabled). Disabling makes the pass a no-op.
Tests
25 new unit tests in
SmartTrailingPunctuationTestscovering all strip shapes, all keep shapes, and the toggle behavior (default-on, disabled, explicitly enabled — with UserDefaults restored after each). FullspeaktypeTestssuite passes locally.Possible follow-up
An AX field-type layer (inspect the focused field's
AXTextFieldsubrole/content-type to strip punctuation contextually) could extend this to sentence-final emails in multi-word dictations — left out to keep this change deterministic and low-risk.