CTC beam search decoder for speech recognition.
Slowing down. Last release over 3 years ago, little activity since. Fine for existing code; think twice for a new project.
pip install pyctcdecodepyctcdecode
A fast and feature-rich CTC beam search decoder for speech recognition written in Python, providing n-gram (kenlm) language model support similar to PaddlePaddle's decoder, but incorporating many new features such as byte pair encoding and real-time decoding to support models like Nvidia's Conformer-CTC or Facebook's Wav2Vec2.
pip install pyctcdecode
Main Features:
- 🔥 hotword boosting
- 🤖 handling of BPE vocabulary
- 👥 multi-LM support for 2+ models
- 🕒 stateful LM for real-time decoding
- ✨ native frame index annotation of words
- 💨 fast runtime, comparable to C++ implementation
- 🐍 easy-to-modify Python code
Quick Start:
from pyctcdecode import build_ctcdecoder
# specify alphabet labels as they appear in logits
labels = [
" ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
"m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
]
# prepare decoder and decode logits via shallow fusion
decoder = build_ctcdecoder(
labels,
kenlm_model_path="/my/dir/kenlm_model.arpa", # either .arpa or .bin file
alpha=0.5, # tuned on a val set
beta=1.0, # tuned on a val set
)
text = decoder.decode(logits)
If the vocabulary is BPE-based, pyctcdecode will automatically recognize that and handled token merging automatically.


