A dictation tool has to make one decision on every single utterance: is this text to type, or an instruction to carry out?
- "undo that" → press Ctrl+Z
- "I want to undo that change" → type those words
Get it wrong in one direction and your words get eaten. Get it wrong in the other and "undo that" appears in your email.
In 2026 the fashionable answer is "send it to an LLM". In YazSes, the offline dictation tool I work on, the answer is mostly a list of regular expressions, and I want to explain why I think that's the right default.
Three tiers, cheapest first
Every utterance goes through a classifier with three tiers:
Tier 0: your macros. An optional table you write yourself. It matches the whole utterance exactly. Say "insert my signature" and get your email signature.
Tier 1: the grammar. A list of anchored regex patterns per language (English and Chinese today). Before matching, surrounding punctuation is stripped and the number words "one" to "ten" become digits, because Whisper writes "Undo three times." one day and "undo 3 times" the next.
_add(r"^undo(?:\s+that)?$", IntentType.EDIT, "undo")
_add(r"^go\s+to\s+line\s+(\d+)$", IntentType.NAVIGATE, "go_to_line", ("n",))
Tier 2: a small local model. Optional, English only, off unless you point it at a local GGUF model file. It only gets a second look at utterances Tier 1 called dictation. If it fails or isn't confident, the utterance is typed as text.
The anchor is the whole trick
Look at the ^ and $. A command must be the entire utterance. "undo that" matches. "I want to undo that change" doesn't, so it's typed.
That one constraint does most of the work. People rarely say a bare command phrase in the middle of dictating prose, and when they say a command, they usually say only the command. The anchor turns that habit into a rule.
Some of what's in the English grammar:
undo · undo that · undo 3 times · delete the last 3 words · save file · copy that · select all · new line · press enter · go to line 42 · page up · go to end of line · go to function main · run the tests · rename this to ... · new class called ...
When a command matches, a dispatcher turns it into keystrokes. "go to line 42" becomes:
if action == "go_to_line":
injector.inject_key_sequence(["ctrl+g"])
injector.inject(args.get("n", ""))
injector.inject_key_sequence(["Return"])
(Those chords assume VS Code-style bindings. Different apps want different keys, and that is a never-ending part of the job.)
The numbers
On a fixed set of 68 command phrases and 80 ordinary dictation lines:
- all 68 phrases produced the expected action,
- 0% of the dictation lines were mistaken for commands,
- a median of 0.02 ms per classification.
That's a small, hand-built test set, not a field study, so read it as "the grammar does what it was designed to do" rather than "it never fails". But compare the cost profile with an LLM call: no model to load, no GPU, no latency anyone can feel, and the same answer every time for the same input. When it gets something wrong, I can read the pattern and see exactly why.
When you want to force it
With one hotkey, YazSes decides automatically. If you'd rather be explicit, set a separate command key:
[hotkey]
command_key = "..." # empty by default
While you hold it, everything is treated as a command, phrases that don't match are dropped instead of typed, and the tray icon turns purple so you can see which mode you're in.
Where "scratch that" lives
You might expect "scratch that" to be in the grammar. It isn't. It's a separate feature (on by default) that deletes the last chunk of text YazSes itself typed, using backspaces. It needs to know exactly what was injected, which the grammar doesn't. And as post 9 in this series explains, "scratch that" in the middle of a sentence is a different, much harder problem.
Your own commands
Macros are where it becomes personal:
yazses features enable macros
# ~/.config/yazses/macros.toml
[[macro]]
trigger = "insert my signature"
type = "text"
text = "Best regards,\nMohsen"
[[macro]]
trigger = "new python function"
type = "snippet"
snippet = "def ${cursor}():\n pass"
Placeholders like ${date}, ${time} and ${clipboard} are filled in when the macro runs, and ${cursor} in a snippet leaves the caret where you put it.
What I took away
- Use the cheapest thing that can be right, and a model for the leftovers. Most of the decision is structural, and structure is what regex is good at.
- Anchor commands to the whole utterance. It's one character on each end and it removes most false positives.
- Fail safe to typing. If anything is unsure, type the words. A command typed as text is visible and easy to delete. Text silently run as a command is not.
- Determinism is a feature. Being able to read why something matched matters a lot when the thing it does is press keys in someone's editor.
YazSes is offline, open source (Apache-2.0) dictation: github.com/MSKazemi/yazses. Macros and snippets: how-to guide.
I wrote this with help from an AI assistant for drafting and editing; the design and opinions are mine, and I checked every example and number against the code.


Top comments (0)