lhotse

lhotse-speechApache-2.0活跃维护

面向语音与多模态机器学习的 Python 数据处理库,提供统一的音频加载、切分、特征提取和数据集管理接口,方便搭建语音识别等训练流水线。

Tools for handling multimodal data in machine learning projects.

v1.33.0发布于 2026-04-20 13:11 UTC1,162star +1 / 7 天300fork同步于 2026-11-10 23:50 UTC

怎么上手

由 README 提炼,执行前请确认
python -m pip install lhotse
硬件要求按 README 说明

README 未说明显存或 GPU 要求;PyTorch 为必需依赖,torchaudio 与 TorchCodec 0.10+ 为可选音频后端,TorchCodec 读视频还需受支持的 FFmpeg 版本

需要 CUDA
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

Lhotse 是准备多模态数据集并构建可扩展 PyTorch 数据管道的 Python 库

面向语音与多模态机器学习的 Python 数据处理库,提供统一的音频加载、切分、特征提取和数据集管理接口,方便搭建语音识别等训练流水线。

核心能力

  • 用 manifest 描述音频、视频、图像和文本数据
  • 惰性流式读取 JSONL manifest 并组合过滤与混洗
  • 加载时对 cut 做截断、填充、混合与增强
  • 按时长动态分批以减少 padding 并支持分布式切分
  • 用 Shar 分片存储并支持索引与断点续训的数据加载

容易踩的坑

master 分支要求 Python 3.11 或更高,稳定版要求需查 PyPI;视频读取需额外安装 torchcodec 并依赖兼容的 FFmpeg;压缩特征、索引 gzip、WebDataset 等能力需另装对应 extras

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v1.33.0
  1. v1.33.0v1.33.0 - Himalayan Vulture最新正式版2026-04-20 · 2026-04-20 13:11 UTC

    Dependencies

    Recipes

    New features

    Fixes

    New Contributors

    Full Changelog: https://github.com/lhotse-speech/lhotse/compare/v1.32.2...v1.33.0

  2. v1.32.2v1.32.2 - Blood Pheasant2026-01-14 · 2026-01-14 15:09 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/lhotse-speech/lhotse/compare/v1.32.1...v1.32.2

  3. v1.32.1v1.32.1 - Blood Pheasant2025-11-24 · 2025-11-24 16:43 UTC
    查看更新说明

    Fix issue with importing Lhotse v1.32.0 on Windows.

    Full Changelog: https://github.com/lhotse-speech/lhotse/compare/v1.32.0...v1.32.1

  4. v1.32.0v1.32.0 - Blood Pheasant2025-11-21 · 2025-11-21 20:04 UTC
    查看更新说明

    Recipes

    New features

    Fixes and enhancements

    New Contributors

    Full Changelog: https://github.com/lhotse-speech/lhotse/compare/1.31.0...v1.32.0

  5. 1.31.0v1.31.1 - Expedition 332025-09-18 · 2025-09-18 21:42 UTC
    查看更新说明

    (skipping 1.31.0 because I accidentally uploaded and deleted this version in the past in PyPI, and can't re-use it now)

    New recipes

    New features

    Fixes and enhancements

    New Contributors

    Full Changelog: https://github.com/lhotse-speech/lhotse/compare/v1.30.3...1.31.0

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    PyPI release Tested Python versions Downloads Unit tests Documentation status Coverage Code style: black Open in Colab arXiv

    Lhotse

    Lhotse is a Python library for preparing multimodal datasets and building scalable PyTorch data pipelines. It provides manifests for audio, video, images, and text, on-the-fly augmentation, dynamic batching, efficient sharded storage, and indexed, resumable dataloading.

    Documentation · Quick start · Tutorials · Contributing · Citation

    Installation

    Install the latest stable release from PyPI:

    python -m pip install lhotse
    

    This README and the latest documentation describe the development version on master, which requires Python 3.11 or later. Some APIs and extras described below may not yet be available in the stable release. The Python badge above lists the versions tested on master; check PyPI for the stable release's requirements.

    To use the development version:

    python -m pip install git+https://github.com/lhotse-speech/lhotse
    

    PyTorch is required; torchaudio and TorchCodec 0.10 or later are optional audio backends. TorchCodec also reads video (python -m pip install torchcodec) and requires an FFmpeg version that it supports. See optional dependencies for additional formats and integrations.

    Quick start

    Download the small public YesNo corpus, prepare its training split, and load a batch of audio and transcripts. This example uses waveforms directly, so it does not need precomputed features or worker processes.

    from pathlib import Path
    
    from torch.utils.data import DataLoader
    
    from lhotse import CutSet
    from lhotse.dataset import (
        AudioSamples,
        DynamicCutSampler,
        K2SpeechRecognitionDataset,
    )
    from lhotse.recipes import download_yesno, prepare_yesno
    
    corpus_dir = download_yesno(target_dir=Path("data"))
    manifests = prepare_yesno(corpus_dir=corpus_dir)["train"]
    cuts = CutSet.from_manifests(
        recordings=manifests["recordings"],
        supervisions=manifests["supervisions"],
        output_path=Path("data") / "cuts.jsonl.gz",
        lazy=True,
    )
    
    dataset = K2SpeechRecognitionDataset(input_strategy=AudioSamples())
    sampler = DynamicCutSampler(cuts, max_duration=60, shuffle=False)
    dataloader = DataLoader(dataset, sampler=sampler, batch_size=None)
    batch = next(iter(dataloader))
    
    print(batch["inputs"].shape)  # Padded waveforms: (batch, samples).
    print(batch["supervisions"]["text"])
    

    The cuts are saved as a JSONL manifest and opened lazily, without loading their audio into memory. DynamicCutSampler streams the cuts into batches with at most 60 seconds of audio, and the dataset loads and pads their waveforms when requested. Despite its name, K2SpeechRecognitionDataset does not require k2.

    Key features

    • Multimodal manifests: represent recordings, supervision segments, images, and audio/video cuts in human-readable manifests with Python and CLI APIs.
    • Lazy processing: stream large JSONL manifests and compose filtering, mapping, shuffling, and dataset blending without loading everything into memory.
    • On-the-fly transforms: truncate, pad, mix, and augment cuts while adjusting their supervision timing; compute features during loading or store them in advance.
    • Dynamic batching: group examples by duration and use dynamic bucketing to reduce padding. Partition data across distributed ranks and dataloader workers to avoid overlapping samples.
    • Efficient storage: use Lhotse Shar for modular, sharded sequential I/O from local or remote storage.
    • Indexed and resumable dataloading: index JSONL and Shar data, pack shard indexes into .idxpack catalogs, and checkpoint supported iterator pipelines. See indexed manifests for the requirements for exact restore, including gzip indexes and worker state.
    • Corpus recipes: prepare standard manifests for commonly used datasets.

    Tutorials

    The notebooks in examples cover the following workflows. Open them on GitHub to read them or in Colab to run them; installation and data requirements are described in each notebook.

    TutorialRun
    Basic Lhotse workflowColab
    Transforming data with cutsColab
    WebDataset integrationColab
    Combining multiple datasetsColab
    Lhotse Shar: modular data formatColab
    Image and video loadingColab
    AIStore batch loading (requires an AIStore endpoint)Colab
    Resumable, indexed dataloading (torchdata for the optional multi-worker example)Colab

    The video notebook reads video frames and audio tracks with TorchCodec 0.10 or later, which also requires FFmpeg. The AIStore notebook uses 100 training and 20 development recordings and creates and removes its own temporary bucket.

    Tutorial presentations and materials

    These conference materials provide additional background and may use older APIs:

    Examples of use

    • Icefall: speech recognition recipes combining Lhotse data pipelines with k2.
    • NVIDIA NeMo: Lhotse dataloading with dynamic batching, dataset mixing, and Shar support.
    • ESPnet example: a minimal integration notebook (Google sign-in may be required).

    Lhotse shares its roots with Kaldi and supports importing and exporting Kaldi data.

    Main ideas

    RecordingSet describes recordings, SupervisionSet describes annotations such as transcripts and speakers, and CutSet combines them into examples that can be reshaped for training. Manifests store metadata and references to the underlying data; audio transforms are applied when the data is loaded.

    Relationships between recordings, supervisions, cuts, and datasets

    Cuts support mixing, truncation, padding, and augmentation. Feature extraction can run on the fly or ahead of training, with optional compressed storage. Lhotse also supports mixing features directly.

    Truncating, padding, and mixing audio cuts

    Optional dependencies

    Install only the extras needed for your workflow. These extras describe master; when using development-only features, include the extras in the source install:

    python -m pip install 'lhotse[checkpoint,gzip] @ git+https://github.com/lhotse-speech/lhotse'
    

    For a published extra, use a quoted requirement such as python -m pip install "lhotse[lilcom]".

    ExtraEnables
    checkpointtorchdata.stateful_dataloader.StatefulDataLoader for multi-worker checkpointing.
    gzipIndexed gzip JSONL with indexed_gzip; keep both .idx and .gzidx sidecars.
    lilcomCompressed features and arrays; lilcom_chunky is the preferred compressed feature backend.
    orjsonFaster JSONL serialization and reading.
    webdatasetWebDataset import/export.
    pillowImage loading with Pillow.
    aistoreAIStore I/O and batch loading; configure AIS_ENDPOINT.
    kaldiKaldi I/O and feature extraction via kaldi-native-io and kaldifeat.
    h5pyHDF5 feature storage.
    dillSerialization of lazy transforms such as lambdas across processes. Also set LHOTSE_DILL_ENABLED=1 or call lhotse.set_dill_enabled(True).

    Additional audio backends, remote storage clients, feature extractors, and SPHERE support are covered in the installation reference.

    Environment variables

    See the configuration reference for audio and I/O backend selection, timing tolerances, remote storage settings, and serialization options. Dill is disabled by default even when installed; enabling it can help with lazy transforms in a PyTorch DataLoader with num_workers > 0.

    Development installation

    Clone the repository, then install the locked development environment with uv:

    git clone https://github.com/lhotse-speech/lhotse
    cd lhotse
    uv sync --locked
    uv run --locked pre-commit install
    

    See the contributor guide for the required uv version, system dependencies, tests, formatting, documentation builds, CPU/CUDA environments, dependency updates, and releases.

    Citation

    If you use Lhotse in research, please cite Lhotse: a speech data representation library for the modern deep learning ecosystem (NeurIPS Data-Centric AI Workshop, 2021). Citation metadata is available in CITATION.cff.

    Acknowledgment

    Some contributions to this project were supported by National Science Foundation CCRI award 2120435.