lhotse-speech/lhotse
Tools for handling multimodal data in machine learning projects.
Lhotse — A data toolkit for speech and multimodal ML
What it is: Lhotse is a Python library that helps you prepare datasets and build data pipelines for machine learning, especially speech recognition. It handles audio, video, images, and text, and plugs into PyTorch's data loading system.
Core idea: three kinds of "manifests"
Lhotse organizes data into three lightweight metadata files (called manifests):
- RecordingSet — describes audio/video recordings (where the files are, durations, etc.)
- SupervisionSet — describes annotations like transcripts and speaker labels
- CutSet — combines recordings and supervisions into training examples that can be sliced, padded, mixed, or augmented
These manifests store metadata and references to the actual data files — not the data itself. Audio is only loaded when you actually request it, which keeps things fast and memory-friendly.
Key capabilities
- Lazy processing — stream large JSONL manifest files without loading everything into memory; compose filtering, mapping, shuffling, and dataset blending on the fly
- On-the-fly transforms — truncate, pad, mix, and augment audio while automatically adjusting annotation timing; compute features during loading or precompute them
- Dynamic batching — group examples by duration to reduce wasted padding; partition data across distributed training ranks and worker processes without overlap
- Efficient storage — a format called Lhotse Shar for sharded, sequential I/O from local or remote storage
- Resumable dataloading — index JSONL and Shar data, pack shard indexes into
.idxpackcatalogs, and checkpoint iterator pipelines so training can resume exactly where it stopped - Corpus recipes — ready-made scripts to prepare standard public datasets
Quick start example
The README shows a minimal workflow: download the small YesNo speech corpus, prepare its training split, and load a batch of audio + transcripts. The key steps:
download_yesno()fetches the corpusprepare_yesno()produces recording and supervision manifestsCutSet.from_manifests()combines them into a lazy JSONL manifestDynamicCutSamplergroups cuts into batches of ≤60 seconds of audio- A
DataLoaderyields padded waveforms and their transcripts
Requirements
- Python 3.11+ (for the development version on
master) - PyTorch is required
- Optional:
torchaudioorTorchCodec(for video) as audio backends - Optional extras for specific features:
gzip(compressed manifests),lilcom(compressed features),webdataset(WebDataset format),pillow(images),aistore(AIStore storage),kaldi(Kaldi compatibility),h5py(HDF5 features),dill(serializing lambdas across processes), and more
Who uses it
- Icefall — speech recognition recipes combining Lhotse with the k2 library
- NVIDIA NeMo — uses Lhotse for dataloading with dynamic batching and Shar support
- ESPnet — has a minimal integration notebook
It shares roots with Kaldi (a classic speech toolkit) and can import/export Kaldi data.
Getting started
python -m pip install lhotse
Then follow the tutorial notebooks in the examples/ folder (also runnable in Google Colab), covering basic workflows, transforming data, WebDataset integration, combining datasets, Shar format, image/video loading, and resumable dataloading.
Citation: If you use it in research, cite the paper "Lhotse: a speech data representation library for the modern deep learning ecosystem" (arXiv:2110.12561).
Related
- Project
- Project
- Project
- Project
- Project