Registry / ai-ml / torchlibrosa

torchlibrosa

JSON →
library0.1.0pypypiunverified

TorchLibrosa provides a PyTorch implementation of core `librosa` audio feature extraction functions, enabling GPU acceleration for tasks such as spectrogram and mel-spectrogram computation. This is particularly beneficial for deep learning pipelines that require faster feature generation on GPUs during training and evaluation. The library aims for numerical results almost identical to CPU-based `librosa` (difference less than 1e-5). The current version is 0.1.0, with an infrequent release cadence; the latest release was in February 2023.

pip install torchlibrosa
INSTALL
IMPORT
SIG · TORCHLIBROSA
T
torchlibrosa
ai-mlpythonv0.1.0
Install
15.2s avg
Import
Disk
481MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
installs and imports cleanly · install 15.2s · import 0.000s · 473MB
481MB installed
● package 481MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Spectrogram
from torchlibrosa import Spectrogram
LogmelFilterBank
from torchlibrosa import LogmelFilterBank
STFT
from torchlibrosa import STFT
ISTFT
from torchlibrosa import ISTFT
torchlibrosa as tl
import torchlibrosa as tl
Common alias for convenience.

This quickstart demonstrates how to extract log mel spectrograms from a batch of audio signals using `torchlibrosa`'s `Spectrogram` and `LogmelFilterBank` modules, designed to work seamlessly within a PyTorch `nn.Sequential` model.

import torch import torchlibrosa as tl batch_size = 16 sample_rate = 22050 win_length = 2048 hop_length = 512 n_mels = 128 # Create a batch of dummy audio (e.g., for GPU processing) batch_audio = torch.empty(batch_size, sample_rate).uniform_(-1, 1) # Instantiate a feature extractor using Sequential for a pipeline feature_extractor = torch.nn.Sequential( tl.Spectrogram( hop_length=hop_length, win_length=win_length, ), tl.LogmelFilterBank( sr=sample_rate, n_mels=n_mels, is_log=False, # Default is true ) ) # Process the audio to get log mel spectrograms batch_feature = feature_extractor(batch_audio) print(f"Input audio shape: {batch_audio.shape}") print(f"Output feature shape (batch_size, 1, time_steps, mel_bins): {batch_feature.shape}")
Debug
Known issues
gotchaPyTorch is a fundamental dependency for `torchlibrosa`, but it is not explicitly listed in the `install_requires` of the `setup.py`. This can lead to a `ModuleNotFoundError` if PyTorch is not installed separately.
fix
Ensure PyTorch is installed manually via `pip install torch` (and `torchvision`, `torchaudio` if needed) or by specifying it in your project's `requirements.txt`.
affects: All versions
gotchaWhile `torchlibrosa` aims to provide 'almost identical features' to `librosa`, a 'numerical difference less than 1e-5' is explicitly stated. Users expecting bit-for-bit identical results to `librosa` on CPU might encounter minor discrepancies.
fix
Be aware of the minor numerical differences. For most deep learning applications, this level of difference is acceptable. If exact parity is critical, consider using `librosa` for CPU-based processing and carefully benchmark results.
affects: All versions
breakingOlder versions of `torchlibrosa` (e.g., 0.0.9) had compatibility issues with specific PyTorch versions (e.g., `torch=1.10.0+cu111`), potentially leading to runtime errors related to internal function calls or argument mismatches.
fix
Upgrade to the latest `torchlibrosa` (0.1.0) and ensure compatibility with your PyTorch version. Check GitHub issues for reported incompatibilities if problems persist.
affects: <=0.0.9
Upgrade
Version history
0.1.0latest on PyPI · released Feb 21, 2023
Audit
Dependencies
numpyrequiredNumerical operations
librosa>=0.9.0requiredProvides reference CPU implementations and utility functions; torchlibrosa aims to replicate its functionality.
torchrequiredCore deep learning framework; torchlibrosa is built on PyTorch.
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
torchlibrosa — pip install torchlibrosa · libregistry