Kaldi Active Grammar: per-utterance grammar switching for Dragonfly voice control
Python Kaldi speech recognition with grammars that can be set active/inactive dynamically at decode-time
At a glance
- What is it?
- Kaldi Active Grammar wraps a forked Kaldi decoder in a Python package so that Dragonfly can activate only the command grammars relevant to the current application, switching them at the start of each utterance. It is a dictation and command-and-control tool, not a general transcription service.
- Who is it for?
- Adopt Kaldi Active Grammar if you are building hands-free command and control for a desktop application and already work inside Dragonfly or Caster, because the per-utterance active/inactive marking is the part that plain Kaldi does not give you. Do not adopt it if you need a streaming transcription service, a macOS or Linux setup with no tolerance for platform-specific wheels, or a permissive licence on a closed-source product.
- Can I use it commercially?
- Yes, with strict conditions. AGPL-3.0 is a network copyleft licence: if people use a modified version over a network, for example as a hosted service, you must offer them its source code under the same licence.
- Is it still maintained?
- Yes. The repository last received commits 83 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- daanzu/kaldi-active-grammar349 ★ · +0
| Repository | 2026-09-21 | 2026-11-25 |
|---|---|---|
| daanzu/kaldi-active-grammar | 349 | 349 |
0 Stars in the last 65 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The problem: monolithic decoding graphs cannot follow the user's context
A conventional Kaldi decoding graph is built once, offline, and then stays fixed for the whole session. Every word in it is a candidate for every utterance. If you want a voice interface that understands "open file" in an editor and "next track" in a media player, you either compile one enormous graph containing both vocabularies, or you maintain separate decoders and switch between them. The first option makes recognition worse because the search space is larger, and the second option means paying the graph-compilation cost repeatedly and losing any shared vocabulary.
Kaldi's newer grammar framework improves on this by allowing multiple independent grammars with nonterminals to be compiled separately and stitched together at decode time. The README is explicit about the remaining gap: in that framework all the grammars are always active and capable of being recognized. The project's contribution is to let each grammar or rule be marked active or inactive dynamically, on a per-utterance basis, set at the beginning of each utterance.
The audience is narrow and specific. This is for people writing Dragonfly or Caster scripts who want a local, offline recognizer whose accuracy improves when the candidate set shrinks. It is not aimed at someone who wants a drop-in transcription API.
How the active/inactive marking and shared dictation grammar fit together
The architecture has three moving parts. First, a fork of Kaldi is compiled into native libraries that ship inside the Python wheel. The README states that these binaries are generated from the author's fork of Kaldi and that the fork is intended only to be used by kaldi-active-grammar directly, not as a stand-alone library. Second, the Python layer exposes grammar objects that the host program marks active or inactive before each decode. Third, Dragonfly supplies the scripting layer: its Kaldi backend, merged as of Dragonfly v0.15.0, translates Dragonfly grammar rules into the active/inactive state the decoder expects.
The design detail worth understanding is the shared dictation grammar. Because command grammars and the dictation grammar are compiled separately and stitched at decode time, the dictation grammar does not have to be baked into every command grammar. The README describes the consequence: command grammars can be compiled quickly without needing to include large-vocabulary dictation directly, and the dictation grammar is shared between all of them.
That matters for iteration speed. Editing a command rule does not force a recompile of a large-vocabulary model. The trade-off is that you now depend on a stitched graph being assembled correctly at runtime, and on the fork of Kaldi that knows how to do the stitching.
Installing kaldi-active-grammar and running a first dictation example
The project is distributed as platform-specific wheels on PyPI. The README and pyproject.toml both state that source distributions are intentionally unsupported, because a usable package must contain the matching native Kaldi library. That means pip will resolve a wheel for your platform; on a platform with no wheel, there is nothing to build from.
A plain install is a single command:
pip install kaldi-active-grammarAfter that, you need a model. The README points to the project releases for a pre-trained general English Kaldi nnet3 chain model trained on roughly 3000 hours of open audio, and notes that improved models are under development. Download the model archive from the releases page and extract it before running anything.
The repository ships example scripts under examples/, including plain_dictation.py, mix_dictation.py, full_example.py and mimic.py. If you only want to see the recognizer work, plain_dictation.py is the shortest path: it uses either your own HCLG.fst file or the included pre-trained dictation model. The examples directory also carries requirements_audio.txt and a test.wav, so microphone and file-based audio paths are both covered. The README does not document the exact command line for each example, so read the script header before running it.
If you are on Windows and want to try the Dragonfly integration without a manual install, the README describes a simple no-install package under Getting Started, and links a demo and a module loader from the Dragonfly repository.
Where the wheel-only policy and the AGPL-3.0 licence bite
Two constraints deserve attention before you build anything on top of this.
The first is distribution. Because only platform-specific wheels are produced, your deployment matrix is whatever the project publishes. There is no supported path to compile from source for an unsupported Python version or CPU architecture, and the setup.py confirms the intent: it forces the wheel to be platform-specific precisely because native libraries are loaded manually at runtime. If your environment cannot use a matching wheel, this project is the wrong tool, regardless of how well the grammar model fits your problem.
The second is licensing. The package is AGPL-3.0. That is a strong copyleft licence with a network-use clause. If you embed this in a service that users interact with over a network, the AGPL's source-availability expectations are likely to reach your combined work in a way the GPL's would not. I am not a lawyer and this is not legal advice; the practical point is that AGPL-3.0 rules out quiet embedding in a closed-source product for most teams, and that is a product decision, not a packaging detail.
Maintenance looks healthy by the only measure available here. The repository is not archived, and the last push was on 2026-09-03. The release history is uneven, though: v3.1.0 and v3.0.0 landed in 2021, and v3.2.0 did not arrive until 2025-11-02. A four-year gap between minor releases tells you something about the cadence to expect.
Dictation-only use, and why a general ASR service is a different tool
The README addresses this directly and with a hint of reluctance: if you just want plain dictation, there is an interface for it, using either your own HCLG.fst file or the included pre-trained model. So the project does cover plain transcription. But that is not where its engineering effort went, and the difference from a hosted ASR API is structural rather than a matter of quality.
A cloud transcription service owns the model, the compute and the updates. You send audio, you get text, and you never think about decoding graphs. Kaldi Active Grammar hands you the opposite: a local decoder, a model you download and manage yourself, and a grammar abstraction whose value only appears when you have more than one context to switch between. If your application has a single fixed vocabulary and no notion of context, the active/inactive mechanism is dead weight, and you have taken on a native dependency, a model download and an AGPL-3.0 obligation for nothing.
The honest comparison is therefore not "this versus Whisper" or "this versus a commercial API" on accuracy, because no accuracy figures are published in the README or the release notes. It is this versus a hosted service on operational shape: local and offline versus remote, grammar-constrained versus open-vocabulary, and copyleft versus whatever terms the service imposes.
Who should adopt Kaldi Active Grammar, and what to check first
Adopt it if you are writing Dragonfly or Caster scripts for hands-free control of a desktop application and you want the recognizer to see fewer candidates when the user is in a specific context. The per-utterance active/inactive marking is the feature that does not exist elsewhere in this form, and the shared dictation grammar keeps command-grammar compiles fast. The bootstrapping note in the README, that development of KaldiAG is done entirely using KaldiAG since v0.2, is the strongest signal that the command-and-control path is the one that actually gets exercised.
Do not adopt it if you need a hosted transcription endpoint, if your platform has no published wheel, or if AGPL-3.0 is incompatible with how you ship software.
What to verify before you commit: confirm a wheel exists on PyPI for your Python version and operating system; download the pre-trained model from the project releases and check its accuracy against your own audio, since the README offers no benchmark numbers; and read the Dragonfly Kaldi engine documentation to confirm the backend version you need, given that the merge landed in Dragonfly v0.15.0 and Caster support arrived with KaldiAG v0.6.0 and Dragonfly v0.16.1.
Editorial conclusion
Adopt Kaldi Active Grammar if you are building hands-free command and control for a desktop application and already work inside Dragonfly or Caster, because the per-utterance active/inactive marking is the part that plain Kaldi does not give you. Do not adopt it if you need a streaming transcription service, a macOS or Linux setup with no tolerance for platform-specific wheels, or a permissive licence on a closed-source product. Before committing, verify three things: that a wheel exists for your Python version and platform on PyPI, that the pre-trained nnet3 chain model from the project releases is the accuracy you can live with, and whether the AGPL-3.0 terms fit how you plan to distribute your code.
Frequently asked questions
What is kaldi-active-grammar used for?
It is used for context-based command and control of computer applications, in the style of the Dragonfly speech recognition framework, on top of the Kaldi engine. The README also notes an interface for plain dictation if that is all you need.
How do I install kaldi-active-grammar?
Install it from PyPI with pip. Only platform-specific wheels are produced and supported; the project states that source distributions are intentionally unsupported because the package must contain the matching native Kaldi library.
Does kaldi-active-grammar include a speech model?
No model is bundled with the package. A compatible general English Kaldi nnet3 chain model, trained on roughly 3000 hours of open audio, is available under the project releases, and the README says improved models are under development.
What licence does kaldi-active-grammar use?
The package is licensed AGPL-3.0, as shown by the licence badge and the LICENSE.txt file in the repository. That is a strong copyleft licence, so check how it interacts with your own distribution plans.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/daanzu-kaldi-active-grammar)Star history chart for your README
[](https://hysenlabs.com/projects/daanzu-kaldi-active-grammar)Was this useful?