PyTorch implemention of part of librosa functions.
Project description
Pytorch implementation of librosa
This codebase provides PyTorch implementation of some librosa functions. The functions can run on GPU. For example, users can extract log mel spectrogram on GPU. The numerical difference of this codebase and librosa is less than 1e-6.
Install
$ pip install torchlibrosa
Examples
import torch
import torchlibrosa as tl
# Data
x = torch.zeros(1, 32000) # (batch_size, samples_num)
# Spectrogram
spectrogram_extractor = tl.stft.Spectrogram(n_fft=1024, hop_length=250)
sp = spectrogram_extractor.forward(x) # (batch_size, 1, time_steps, freq_bins)
# Log mel spectrogram
logmel_extractor = tl.stft.LogmelFilterBank(sr=32000, n_fft=1024, n_mels=64)
logmel = logmel_extractor.forward(sp) # (batch_size, 1, time_steps, freq_bins)
# STFT
stft_extractor = tl.stft.STFT(n_fft=1024, hop_length=250)
(real, imag) = stft_extractor.forward(x)
"""real: (batch_size, 1, time_steps, freq_bins), imag: (batch_size, 1, time_steps, freq_bins)"""
# ISTFT
istft_extractor = tl.stft.ISTFT(n_fft=1024, hop_length=250)
y = istft_extractor.forward(real, imag, x.shape[-1]) # (batch_size, samples_num)
More examples
python3 torchlibrosa/stft.py
Cite
[1] Kong, Qiuqiang, Yin Cao, Turab Iqbal, Yuxuan Wang, Wenwu Wang, and Mark D. Plumbley. "PANNs: Large-Scale Pretrained Audio Neural Networks for Audio Pattern Recognition." arXiv preprint arXiv:1912.10211 (2019).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
torchlibrosa-0.0.4.tar.gz
(8.3 kB
view hashes)
Built Distribution
Close
Hashes for torchlibrosa-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a07f326f59a299aa67077bda442669ab25a4b1d8c9e8ad46fb85c5a3b7605abc |
|
MD5 | eff17632db931df3235958338990faa1 |
|
BLAKE2b-256 | 09a8663a8b3e483e910051cb6b5f60b281517d22d0bdb51686d5fc8bee460041 |