abbreviate
The community/core/abbreviate directory provides a streamlined mechanism for voice-dictating common programming, technical, and general-purpose abbreviations.
This directory contains the core implementation that maps longer spoken phrases to their short-form equivalents, allowing users to write compact code and text efficiently using Talon.
Key Components
- abbreviate.py: This Python file defines the abbreviations module, sets up the list structures, and handles the registration of spoken-form-to-abbreviation mappings.
How It Works
The system registers a list (user.abbreviation) and a capture pattern to intercept voice commands prefixed with "brief".
1. Defining the Capture Pattern
The module registers a custom Talon capture rule:
@mod.capture(rule="brief {user.abbreviation}")
def abbreviation(m) -> str:
return m.abbreviation
This allows users to say "brief <phrase>" to output the abbreviated version of a word. For example:
* Saying "brief application" yields app.
* Saying "brief regular expression" yields regex.
* Saying "brief as far as i know" yields afaik.
2. Managing and Loading Abbreviations
The script includes a large static dictionary of default mappings, including technical terms (e.g., "control flow graph": "cfg"), geographical regions (e.g., "alberta": "ab"), and common chat acronyms (e.g., "away from keyboard": "afk").
To support user customization, abbreviate.py integrates with Talon's user settings using the @track_csv_list decorator:
@track_csv_list(
"abbreviations.csv", headers=("Abbreviation", "Spoken Form"), default=abbreviations
)
def on_abbreviations(values):
...
This decorator monitors a user-configurable CSV file (abbreviations.csv). When changes are made to the CSV, the system dynamically updates the underlying Talon list.
3. Self-Referential Matching
To make dictation as natural as possible, abbreviate.py enables "self-referential" speaking. If an abbreviation itself contains only letters and spaces (e.g., app), it is automatically added to the spoken forms list. This means a user can say either:
* "brief application" -> app
* "brief app" -> app
This fallback logic handles natural variations in voice dictation seamlessly.