Skip to content

feat: smart trailing punctuation for non-prose dictations#110

Open
karansinghgit wants to merge 1 commit into
mainfrom
fix/smart-trailing-punctuation
Open

feat: smart trailing punctuation for non-prose dictations#110
karansinghgit wants to merge 1 commit into
mainfrom
fix/smart-trailing-punctuation

Conversation

@karansinghgit

Copy link
Copy Markdown
Owner

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:

  • Emailroy@example.com.roy@example.com
  • URL — scheme, www., or bare domain with a plausible TLD (final label ≥ 2 letters, so U.S. is not treated as a domain)
  • Number — decimals, thousands separators, versions, phone numbers with spaces/parens/dashes
  • Single tokenHello.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 (... / ), ? !, and U.S.-style abbreviations.

It runs in TranscriptionManager.transcribe after DictionaryService, 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 SmartTrailingPunctuationTests covering all strip shapes, all keep shapes, and the toggle behavior (default-on, disabled, explicitly enabled — with UserDefaults restored after each). Full speaktypeTests suite passes locally.

Possible follow-up

An AX field-type layer (inspect the focused field's AXTextField subrole/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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant