Skip to main content

Data preparation for speech processing models training.

Project description

PyPI Status Python Versions PyPI Status Build Status Documentation Status codecov Code style: black Open In Colab

Lhotse

Lhotse is a Python library aiming to make speech and audio data preparation flexible and accessible to a wider community. Alongside k2, it is a part of the next generation Kaldi speech processing library.

⚠️ Lhotse is not fully stable yet - while many features are already implemented, the APIs are still subject to change! ⚠️

About

Main goals

  • Attract a wider community to speech processing tasks with a Python-centric design.
  • Accommodate experienced Kaldi users with an expressive command-line interface.
  • Provide standard data preparation recipes for commonly used corpora.
  • Provide PyTorch Dataset classes for speech and audio related tasks.
  • Flexible data preparation for model training with the notion of audio cuts.
  • Efficiency, especially in terms of I/O bandwidth and storage capacity.

Tutorials

We currently have the following tutorials available in examples directory:

  • Basic complete Lhotse workflow Colab
  • Transforming data with Cuts Colab
  • (experimental) WebDataset integration Colab
  • How to combine multiple datasets Colab

Examples of use

Check out the following links to see how Lhotse is being put to use:

  • Icefall recipes: where k2 and Lhotse meet.
  • Minimal ESPnet+Lhotse example: Colab

Main ideas

Like Kaldi, Lhotse provides standard data preparation recipes, but extends that with a seamless PyTorch integration through task-specific Dataset classes. The data and meta-data are represented in human-readable text manifests and exposed to the user through convenient Python classes.

image

Lhotse introduces the notion of audio cuts, designed to ease the training data construction with operations such as mixing, truncation and padding that are performed on-the-fly to minimize the amount of storage required. Data augmentation and feature extraction are supported both in pre-computed mode, with highly-compressed feature matrices stored on disk, and on-the-fly mode that computes the transformations upon request. Additionally, Lhotse introduces feature-space cut mixing to make the best of both worlds.

image

Installation

Lhotse supports Python version 3.6 and later.

Pip

Lhotse is available on PyPI:

pip install lhotse

To install the latest, unreleased version, do:

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

Hint: for up to 50% faster reading of JSONL manifests, use: pip install lhotse[orjson] to leverage the orjson library.

Development installation

For development installation, you can fork/clone the GitHub repo and install with pip:

git clone https://github.com/lhotse-speech/lhotse
cd lhotse
pip install -e '.[dev]'
pre-commit install  # installs pre-commit hooks with style checks

# Running unit tests
pytest test

# Running linter checks
pre-commit run

This is an editable installation (-e option), meaning that your changes to the source code are automatically reflected when importing lhotse (no re-install needed). The [dev] part means you're installing extra dependencies that are used to run tests, build documentation or launch jupyter notebooks.

Extra dependencies

For reading older LDC SPHERE (.sph) audio files that are compressed with codecs unsupported by ffmpeg and sox, please run:

# CLI
lhotse install-sph2pipe

# Python
from lhotse.tools import install_sph2pipe
install_sph2pipe()

It will download it to ~/.lhotse/tools, compile it, and auto-register in PATH. The program should be automatically detected and used by Lhotse.

Examples

We have example recipes showing how to prepare data and load it in Python as a PyTorch Dataset. They are located in the examples directory.

A short snippet to show how Lhotse can make audio data preparation quick and easy:

from torch.utils.data import DataLoader
from lhotse import CutSet, Fbank
from lhotse.dataset import VadDataset, SimpleCutSampler
from lhotse.recipes import prepare_switchboard

# Prepare data manifests from a raw corpus distribution.
# The RecordingSet describes the metadata about audio recordings;
# the sampling rate, number of channels, duration, etc.
# The SupervisionSet describes metadata about supervision segments:
# the transcript, speaker, language, and so on.
swbd = prepare_switchboard('/export/corpora3/LDC/LDC97S62')

# CutSet is the workhorse of Lhotse, allowing for flexible data manipulation.
# We create 5-second cuts by traversing SWBD recordings in windows.
# No audio data is actually loaded into memory or stored to disk at this point.
cuts = CutSet.from_manifests(
    recordings=swbd['recordings'],
    supervisions=swbd['supervisions']
).cut_into_windows(duration=5)

# We compute the log-Mel filter energies and store them on disk;
# Then, we pad the cuts to 5 seconds to ensure all cuts are of equal length,
# as the last window in each recording might have a shorter duration.
# The padding will be performed once the features are loaded into memory.
cuts = cuts.compute_and_store_features(
    extractor=Fbank(),
    storage_path='feats',
    num_jobs=8
).pad(duration=5.0)

# Construct a Pytorch Dataset class for Voice Activity Detection task:
dataset = VadDataset()
sampler = SimpleCutSampler(cuts, max_duration=300)
dataloader = DataLoader(dataset, sampler=sampler, batch_size=None)
batch = next(iter(dataloader))

The VadDataset will yield a batch with pairs of feature and supervision tensors such as the following - the speech starts roughly at the first second (100 frames):

image

Project details


Download files

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

Source Distribution

lhotse-1.5.0.tar.gz (369.3 kB view details)

Uploaded Source

Built Distribution

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

lhotse-1.5.0-py3-none-any.whl (490.9 kB view details)

Uploaded Python 3

File details

Details for the file lhotse-1.5.0.tar.gz.

File metadata

  • Download URL: lhotse-1.5.0.tar.gz
  • Upload date:
  • Size: 369.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for lhotse-1.5.0.tar.gz
Algorithm Hash digest
SHA256 e244d1d6be0fb415716c17da21ef00ba380fd9271d7bfb341a85ebbeb323f615
MD5 47bc864d708fe9a24540ff7ca7d5b989
BLAKE2b-256 f74acf5f3118bad84390cee5de8b26a04c2eff1cf6634be710b2767d82dc9d8c

See more details on using hashes here.

File details

Details for the file lhotse-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: lhotse-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 490.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for lhotse-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af9528ba5f4186f4c1bc6808e1a8e1bb5ed9f533c7110e93be49e81660e26b7e
MD5 bd93221695f7bbbc69cf74a878e88314
BLAKE2b-256 9800cae11e8a6f9d0e1d33c3eab211b7028086b2d93f4ce867c0216996cfbb72

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