Skip to main content

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

Project description

Kaldi Active Grammar

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

PyPI - Status PyPI - Version PyPI - Python Version PyPI - Wheel PyPI - Downloads Batteries-Included

Donate Donate Donate Donate [GitHub is currently matching all my donations $-for-$.]

Python package developed to enable context-based command & control of computer applications, as in the Dragonfly speech recognition framework, using the Kaldi automatic speech recognition engine.

Normally, Kaldi decoding graphs are monolithic, require expensive up-front off-line compilation, and are static during decoding. Kaldi's new grammar framework allows multiple independent grammars with nonterminals, to be compiled separately and stitched together dynamically at decode-time, but all the grammars are always active and capable of being recognized.

This project extends that to allow each grammar/rule to be independently marked as active/inactive dynamically on a per-utterance basis (set at the beginning of each utterance). Dragonfly is then capable of activating only the appropriate grammars for the current environment, resulting in increased accuracy due to fewer possible recognitions. Furthermore, the dictation grammar can be shared between all the command grammars, which can be compiled quickly without needing to include large-vocabulary dictation directly.

Features

  • Binaries: The Python package includes all necessary binaries for decoding on Linux or Windows. Available on PyPI.
    • Binaries are generated from my fork of Kaldi, which is only intended to be used by kaldi-active-grammar directly, and not as a stand-alone library.
  • Pre-trained model: A compatible general English Kaldi nnet3 chain model is trained on ~1200 hours of open audio. Available under project releases.
    • An improved model is under development.
  • Plain dictation: Do you just want to recognize plain dictation? Seems kind of boring, but okay! There is an interface for plain dictation (see below), using either your specified HCLG.fst file, or KaldiAG's included pre-trained dictation model.
  • Dragonfly/Caster: A compatible backend for Dragonfly is under development in the kaldi branch of my fork, and has been merged as of Dragonfly v0.15.0.
    • See its documentation, try out a demo, or use the loader to run all normal dragonfly scripts.
    • You can try it out easily on Windows using a simple no-install package: see Getting Started below.
    • Caster is supported as of KaldiAG v0.6.0 and Dragonfly v0.16.1.
    • Support for KaldiAG v1.0.0 has been merged as of Dragonfly v0.18.0! Improvements include Direct Parsing, Python3, Unicode, Grammar/Rule Weights, Generalized Alternative Dictation, and various bug fixes & optimizations. For details and previous versions' improvements, see project releases.

Donations are appreciated to encourage development.

Donate Donate Donate Donate [GitHub is currently matching all my donations $-for-$.]

Related Repositories

Getting Started

Want to get started quickly & easily on Windows? Available under project releases:

  • kaldi-dragonfly-winpython: A self-contained, portable, batteries-included (python & libraries & model) distribution of kaldi-active-grammar + dragonfly2. Just unzip and run!
  • kaldi-dragonfly-winpython-dev: [more recent development version] A self-contained, portable, batteries-included (python & libraries & model) distribution of kaldi-active-grammar + dragonfly2. Just unzip and run!
  • kaldi-caster-winpython-dev: [more recent development version] A self-contained, portable, batteries-included (python & libraries & model) distribution of kaldi-active-grammar + dragonfly2 + caster. Just unzip and run!

Otherwise...

Setup

Requirements:

  • Python 2.7 or 3.4+; 64-bit required!
    • Microphone support provided by pyaudio package
  • OS: Linux or Windows; macOS planned if there is interest
  • Only supports Kaldi left-biphone models, specifically nnet3 chain models, with specific modifications
  • ~1GB+ disk space for model plus temporary storage and cache, depending on your grammar complexity
  • ~500MB+ RAM for model and grammars, depending on your model and grammar complexity

Install Python package, which includes necessary Kaldi binaries:

pip install kaldi-active-grammar

Download compatible generic English Kaldi nnet3 chain model from project releases. Unzip the model and pass the directory path to kaldi-active-grammar constructor.

Or use your own model. Standard Kaldi models must be converted to be usable. Conversion can be performed automatically, but this hasn't been fully implemented yet.

Troubleshooting

  • Errors installing
    • Make sure you're using a 64-bit Python.
    • Update your pip by executing pip install --upgrade pip.

Documentation

Documentation is sorely lacking currently. To see example usage, examine the backend for Dragonfly.

Plain dictation interface

import sys, wave
from kaldi_active_grammar import PlainDictationRecognizer
recognizer = PlainDictationRecognizer()  # Or supply non-default model_dir, tmp_dir, or fst_file
wave_file = wave.open(sys.argv[1], 'rb')
data = wave_file.readframes(wave_file.getnframes())
output_str, likelihood = recognizer.decode_utterance(data)
print(repr(output_str), likelihood)  # -> 'alpha bravo charlie' 1.1923989057540894

Contributing

Issues, suggestions, and feature requests are welcome & encouraged. Pull requests are considered, but project structure is in flux.

Donations are appreciated to encourage development.

Donate Donate Donate Donate [GitHub is currently matching all my donations $-for-$.]

Author

License

This project is licensed under the GNU Affero General Public License v3 (AGPL-3.0-or-later). See the LICENSE.txt file for details. If this license is problematic for you, please contact me.

Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

kaldi_active_grammar-1.2.0-py2.py3-none-win_amd64.whl (31.8 MB view details)

Uploaded Python 2Python 3Windows x86-64

kaldi_active_grammar-1.2.0-py2.py3-none-manylinux2010_x86_64.whl (30.2 MB view details)

Uploaded Python 2Python 3manylinux: glibc 2.12+ x86-64

File details

Details for the file kaldi_active_grammar-1.2.0-py2.py3-none-win_amd64.whl.

File metadata

  • Download URL: kaldi_active_grammar-1.2.0-py2.py3-none-win_amd64.whl
  • Upload date:
  • Size: 31.8 MB
  • Tags: Python 2, Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15

File hashes

Hashes for kaldi_active_grammar-1.2.0-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 f487b7812e8e874f13ecfd48ff8417ed8d2686b0a2edaabb79e00b00d76bd5e7
MD5 a722a1a120af7268512f6bc2774b8bc1
BLAKE2b-256 d478680a95655c64a758a735babc154581f1ffcf3e62a51517e8ff34ec7f75f6

See more details on using hashes here.

File details

Details for the file kaldi_active_grammar-1.2.0-py2.py3-none-manylinux2010_x86_64.whl.

File metadata

  • Download URL: kaldi_active_grammar-1.2.0-py2.py3-none-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 30.2 MB
  • Tags: Python 2, Python 3, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.13

File hashes

Hashes for kaldi_active_grammar-1.2.0-py2.py3-none-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 05f9370c90bb6ff69612aee1755d89582b51f8aaed8aacbc79dce09dcb8046a3
MD5 0655e305475c5ecb55c0342ace9b9577
BLAKE2b-256 3601f6722a950f48124ac688f6fc8d90e7def809fe607effe0a80d7e86adb983

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page