Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Incremental speech recognition decoder for Kaldi NNET2 and GMM models with Python bindings (tested with Python 2.7 and Python 3.4).

Python module documentation is here.

Example Usage

from alex_asr import Decoder
import wave
import struct
import os

# Load speech recognition model from "asr_model_dir" directory.
decoder = Decoder("asr_model_dir/")

# Load audio frames from input wav file.
data ="input.wav")
frames = data.readframes(data.getnframes())

# Feed the audio data to the decoder.

# Get and print the best hypothesis.
prob, word_ids = decoder.get_best_path()
print " ".join(map(decoder.get_word, word_ids))

Build & Install

Ubuntu 14.04 requirements installation

apt-get update
apt-get install -y build-essential libatlas-base-dev python-dev python-pip git wget gfortran g++ unzip zlib1g-dev automake autoconf libtool subversion
pip install Cython


$ python install


  • The decoder takes one argument model_dir for initialization. It is a directory with the decoder model and its configuration.
  • It expects that a file called alex_asr.conf is contained in it. This file specifies filenames of all other configs, and adheres to Kaldi configuration standards (i.e. one option per line in a text file).
  • All filenames specified in this config are relative to model_dir

Example of alex_asr.conf that should reside in model_dir:

--model_type=nnet2     # Supported model types are nnet2 (nnet2::AmNnet) and gmm (AmDiagGmm)
--model=final.mdl      # Filename of the mdl file for the decoder.
--hclg=HCLG.fst        # Filename of the fst file with decoding HCLG fst.
--words=words.txt      # Filename with a list of words (each line contains: ""<word> <word-id>").
--mat_lda=final.mat    # Filaneme of the LDA transform matrix.
--mat_cmvn=cmvn.mat    # Filename of the CMVN matrix with global CMVN stats used for OnlineCMVN estimator.
--use_lda=true         # true/false; Says whether to use LDA transform specified by --mat_lda on MFCC features.
--use_ivectors=true    # true/false; Says whether to use Ivector features for decoding
                       # (depends on your decoder). If set to true, you need to also specify --cfg_ivector
                       # with configuration for the ivector extractor.
--use_cmvn=false       # true/false; Says whether to do OnlineCMVN estimation. Uses --mat_cmvn as an initial
                       # matrix for OnlineCMVN estimation. If set to true, --cfg_cmvn must specify a file
                       # with configuration for the estimator.
--use_pitch=false      # true/false. Whether to use pitch feature. If true, --cfg_pitch must specify a file
                       # with configuration of the pitch extractor.
--bits_per_sample=16   # 8/16; How many bits per sample frame?

# These parameters specify filenames of configuration of the particular parts of the decoder. Detailed below.

Decoder configuration.

Example decoder.cfg:



Decodable configuration.

Example decodable.cfg:



MFCC configuration

Example mfcc.cfg:



Online CMVN configuration

Online CMVN configuration is needed when you set --use_cmvn=true.


Splice configuration

Example splice.cfg:



Endpoint configuration

Endpointing configuration is needed if you intend to call EndpointDetected and TrailingSilenceLength functions of the Decoder.

Example endpoint.cfg:


IVector configuration

Ivector configuration is needed if you set --use_ivectors=true.

Example ivector.cfg:


Pitch configuration

Pitch configuration is neede if you set --use_pitch=true.



Regenerate and publish documentation

Provided you have built the module, the documentation can be built by the following commads:

$ cd doc
$ bash 

This uses sphinx to build the documentation and pushes it as a GitHub page of the repository.


Copyright 2015 Charles University in Prague

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Author: Lukas Zilka (

Adapted from Ondra Platek's PyKaldi

Integrated Cython code from:


Online decoder for Kaldi NNET2 and GMM speech recognition models with Python bindings.







No packages published