daanzu/kaldi-active-grammar

Python Kaldi speech recognition with grammars that can be set active/inactive dynamically at decode-time

kaldi‑active‑grammar – Dynamic‑grammar speech recognition for Python

What it is

  • A Python package that wraps the Kaldi ASR engine and adds active‑grammar support. Grammars (sets of command phrases) can be turned on or off for each utterance, letting a downstream system such as Dragonfly or Caster only listen for the commands that make sense in the current context.

Why it matters

  • Standard Kaldi decoding graphs are static and must be compiled offline, which makes context‑dependent command‑and‑control cumbersome. This library lets you compile many small grammars once and then stitch them together at decode‑time, activating only the relevant ones. Fewer active rules → less confusion → higher recognition accuracy.

Key features (as listed in the README)

  • Binaries included – platform‑specific wheels (Windows, Linux, macOS) ship the required Kaldi native libraries, so you don’t need to build Kaldi yourself.
  • Pre‑trained English model – ~3000 h of open‑source audio, ready to use out‑of‑the‑box; model files are distributed with the releases.
  • Plain dictation mode – you can fall back to free‑form speech recognition using the supplied HCLG.fst or the bundled model.
  • Dragonfly / Caster backend – a Kaldi engine implementation for the popular Dragonfly command‑framework (merged upstream in Dragonfly v0.15.0) and support for the Caster voice‑control system (v0.6.0+).
  • Dynamic activation API – low‑level Python API where you supply a list of rule IDs that are active for the upcoming utterance; an empty list disables all rules, None continues the previous utterance.
  • Pronunciation handling – optional G2P (g2p_en) for offline word‑generation or online lookup via requests.
  • Self‑contained Windows bundles – zip files (kaldi‑dragonfly‑winpython*) that include Python, the library, and the model for a “just unzip and run” experience.

Typical workflow

  1. Install the wheel: pip install kaldi-active-grammar (or pip install "dragonfly2[kaldi]" to get the Dragonfly backend).
  2. Download the pre‑trained model from the GitHub releases page and point the library at its directory.
  3. Define grammars (rules) using the Compiler/KaldiRule classes or, more conveniently, via Dragonfly’s rule syntax.
  4. For each utterance, pass the list of active rule IDs to the decoder and receive the recognized rule text.

Getting started quickly (Windows)

  • Grab one of the kaldi‑dragonfly‑winpython zip bundles, unzip, and run the provided demo script. No separate Python or Kaldi installation is required.

Installation notes

  • Requires 64‑bit Python 3.6+.
  • On Windows you may need the VC 2017+ redistributable (VCRUNTIME140.dll).
  • Source distributions are not provided; you must use the binary wheels or build Kaldi yourself via the fork referenced in the docs.

Documentation & resources

  • Architecturedocs/kaldi-fork-architecture.md
  • Building from sourceBUILDING.md
  • TestingTESTING.md
  • Examplesexamples/ (plain dictation, live microphone, mixed command/dictation)
  • Dragonfly integration guide – linked from the README and the Dragonfly docs.

Who it’s for

  • Developers building voice‑controlled desktop applications that need context‑aware command sets.
  • Researchers experimenting with dynamic grammar selection in low‑latency ASR.
  • Hobbyists who want a ready‑to‑run Kaldi‑based speech recogniser on Windows, Linux or macOS.

License

  • AGPL‑3.0 (commercial use requires compliance with the license or a separate arrangement with the author).

All details above are taken directly from the repository’s README; no additional features have been inferred.

Related

  • Project
  • Project
  • Project
  • Project
  • Project