numbers
This directory contains the core implementation for recognizing, parsing, and formatting spoken numbers (both cardinal and ordinal) within the Talon voice recognition configuration. It provides robust parsing logic to translate human-spoken numeric strings—including complex scaled figures, decimals, and negative numbers—into standardized digit strings, integers, or formatted prose.
The directory consists of python-based parsing logic, Talon list/capture definitions, and corresponding .talon files that map voice commands to text insertion.
Cardinal Numbers
The parsing and generation of standard cardinal numbers is managed primarily by numbers.py. This file defines standard mapped English number terms (digits, teens, tens, and scales like "hundred" or "million") and uses helper functions to evaluate spoken streams:
- Small Numbers: Built using
get_spoken_form_under_one_hundred, which dynamically sets up a list of spoken representations for values0through99(supporting both standard words and double-digit variations like "five one" for51). - Scale Parsing: Uses a left-to-right iterative parser (
parse_scale) to resolve scale hierarchies. It ensures complex phrases like "one hundred and five thousand" resolve mathematically to105000by processing lower-level scales (like "hundred") before aggregating them into higher-level scales (like "thousand").
numbers.py exposes several reusable Talon captures:
* digits and digit_string (e.g., "one two three" -> 123)
* number and number_string (e.g., "one hundred twenty three" -> 123)
* number_signed (allowing "minus" or "negative" prefixes)
* Formatted variations such as number_prose_with_dot (using "dot" or "point"), number_prose_with_comma, and number_prose_with_colon (for times/ratios).
The activation of cardinal number commands is split between two separate Talon files to prevent voice trigger collisions depending on the user's active context:
- numbers_prefixed.talon: Employs a safe fallback mechanism. It maps the capture
<user.number_prose_prefixed>to dictate numbers, requiring a prefix word like "numb" or "numeral" (e.g., "numb forty two" ->42). This limits accidental number insertions during regular dictation. - numbers_unprefixed.talon: Permits direct, unprefixed number transcription (e.g., saying "forty two" directly outputs
42). This mode is conditional and only active if theuser.unprefixed_numberstag is enabled and conflicting modalities (like continuous scrolling or active mouse grids) are disabled.
Ordinal Numbers
Ordinal number recognition (such as "first", "second", "twenty-third") is handled independently by ordinals.py.
This script:
* Pre-computes map tables for ordinals up to 99.
* Assembles complex combinations programmatically (e.g., combining the tens word "twenty" with the ordinal unit "third" to map "twenty third" to "23").
* Registers two main captures: <user.ordinals> (representing numbers 1 through 99) and <user.ordinals_small> (representing numbers 1 through 20). These are highly useful in other parts of the Talon configuration for zero-indexed or one-indexed selections (e.g., "go to the third line").