Add Phrases: trigger → snippet substitution for dictated text#777
Open
mattmoran56 wants to merge 3 commits into
Open
Add Phrases: trigger → snippet substitution for dictated text#777mattmoran56 wants to merge 3 commits into
mattmoran56 wants to merge 3 commits into
Conversation
04e55e0 to
4ce275b
Compare
Add a Phrases sidebar where users define trigger → snippet pairs. After Whisper transcribes speech, each trigger is replaced with its snippet while surrounding text is preserved. Matching is case-insensitive and word-boundary aware; longer triggers win when they overlap.
Cover basic substitution, trailing punctuation preservation, case insensitivity, word boundaries, longest-match priority, regex metacharacter escaping, multi-line snippets, blank-trigger handling, multiple occurrences, and empty inputs. Add an npm test script that runs the existing node:test suite under test/.
Replace English fallbacks for the new phrases.* keys with translated copy in de, es, fr, it, ja, pt, ru, zh-CN, zh-TW. Each non-English phrases block carries a _comment noting the translations were AI-generated (Claude) and have not been reviewed by a native speaker.
485ad05 to
0219405
Compare
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.
Summary
Adds a new Phrases section to the Control Panel sidebar where users define trigger → snippet pairs. After Whisper transcribes their speech, each trigger phrase is replaced with the corresponding snippet while surrounding text is preserved verbatim.
Use cases: dictate "my email" and have it expand to an email address; dictate "message template one best wishes Matt" and have the template expand while "best wishes Matt" stays intact.
Changes
src/components/PhrasesView.tsx) with empty state, inline-editable trigger / snippet rows, auto-growing snippet textarea (CSSfield-sizing: content), and add/delete controlsControlPanelSidebar.tsxandControlPanel.tsx(newphrasesview,Replaceicon)src/utils/phraseSubstitution.js) — case-insensitive, Unicode-aware word boundaries (\p{L}\p{N}), longer triggers win when they overlap, regex metacharacters escaped, blank triggers skippedaudioManager.processAudioafter reasoning, before paste/save — covers every transcription provider (local Whisper, Parakeet, OpenWhispr cloud, OpenAI). Raw transcript is preserved in DB; only the substituted text reaches the clipboardcustomPhrasesinsettingsStore(localStorage, mirroringcustomDictionary); typedCustomPhraseshape insrc/types/phrases.tssidebar.phrases+phrases.*keys translated into all 10 locales (en source + de, es, fr, it, ja, pt, ru, zh-CN, zh-TW). Each non-Englishphrasesblock carries a_commentfield noting the translations were AI-generated by Claude and have not been reviewed by a native speakertest/helpers/phraseSubstitution.test.js(12 cases) usingnode:test, matching the repo's existing test convention. Adds annpm testscript that runs the fulltest/**/*.test.jssuite (24 tests total alongside the 12 pre-existing helper tests)Out of scope (follow-up)
processAudio; phrase substitution only runs on the post-transcription path for v1{{date}}etc.) is not supportedTesting
npm run lint— 0 errors (3 pre-existing warnings unrelated to this change)npm run typecheck— cleannpm test— 24/24 pass (12 new + 12 pre-existing). New cases: basic substitution, trailing punctuation preserved, case-insensitive matching, plural word-boundary non-match, longest-trigger-wins, empty-list no-op, leading-position match, multi-line snippets, regex-metachar escaping, blank-trigger handling, multiple occurrences, empty textnode scripts/check-i18n.js— locale keys and placeholders consistent across all 10 localesmy email→me@example.com, verify it persists across reloads (localStorage)message template one→ multi-line template — trailing ", best wishes Matt" preserved verbatim after the inserted templatemy email— does not match (word-boundary respect verified end-to-end)rawTextpreserved in DB), while clipboard/preview show the substituted text📝 Personal note: this is one of my favourite features on the paid Whispr apps — it'd be awesome to see it land here. Happy to revise direction, scope, or naming based on feedback!