How dictation-toolbox/caster works
Project Type and Purpose
• Caster is an open‑source, full‑application toolkit (Python package) for controlling your computer by voice.
• It builds on the Dragonfly speech‑recognition framework and integrates with multiple speech engines (Dragon NaturallySpeaking, Kaldi, Windows Speech Recognition).
• It provides a plugin‑style architecture of “rules” and “contexts” for universal editing/navigation, application‑specific commands, and language‑specific coding constructs.
Top‑Level Architectural Layers
A. External Interfaces
• Speech Engines (Dragonfly adapters for Kaldi, Dragon, WSR)
• Third‑party services: Sikuli (via XMLRPC server), Aenea, AutoHotkey
B. Core Caster Engine
• Control & Nexus (castervoice/lib/ctrl, nexus.py): orchestrates engine setup, grammar activation, continuous command recognition (CCR), dependency management
• Configuration (config_toml, config_base): loads user settings from TOML or default dir
• Grammar & Rule Manager (grammar_container, grammar_manager, managed_rule, rule_maker): dynamically loads rule modules, activates/deactivates them based on context
• CCR Merger (lib/merge/ccrmerging2): merges multiple small commands into continuous flows
• Transformers (transformers_runner, text_replacer): apply user or built‑in transformers to map voice specs to actions
C. Asynchronous Subsystem (castervoice/asynch)
• Events & Observables (e.g., hmc, mouse, HUD, settingswindow): run non‑blocking command flows, pop‑up dialogs, directory pickers
D. OS‑Interaction Layer
• Actions (lib/actions), Keyboard & Mouse controllers, Virtual Desktops, Clipboard, Window Management, Printer, Terminal integration
Component Relationships & Data Flow
• Audio Input → Speech Engine Adapter → Dragonfly → Caster Control
• Caster Control invokes Grammar Manager → finds matching Rule(s)
• Rule invocation → Action Module → OS‑Interaction (keystrokes, mouse moves, window ops)
• For CCR: incoming rule fragments → CCR Merger → Transformers → final command
• Asynchronous requests (e.g., “choose directory”) → Asynch subsystem → UI/Dialogs → result fed back into rule flow
• External integrations (Sikuli, Aenea) invoked via dedicated rule modules that communicate over XMLRPC or sockets
Key Architectural Patterns & Principles
• Plugin/Modular pattern: rules for every application and language live in separate directories; loaded/unloaded at runtime
• Observer pattern: reload observables for hot‑reloading rules, timer/manual observables
• Strategy pattern: merging strategies (classic merging, compatibility, sorting) for CCR
• Separation of concerns: control flow, grammar management, merge/transform, action execution, async UI, and external integrations are in distinct packages
• Configuration abstraction: base vs TOML config providers