Asteroid Filterbanks

0.4.0 · active · verified Fri Apr 10

Asteroid's filterbanks is a Python library providing various filterbank implementations for audio signal processing within deep learning contexts, primarily using PyTorch. It is designed to be a modular toolkit for researchers working on audio source separation. The library is actively maintained with frequent updates, particularly concerning PyTorch compatibility, with the current version being 0.4.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate a `FreeFB` filterbank, wrap it with an `Encoder` to transform a waveform into a time-frequency representation, and then use a `Decoder` to reconstruct the waveform. This is a common pattern for learnable front-ends in audio processing models.

import torch
from asteroid_filterbanks.enc_dec import Encoder, Decoder
from asteroid_filterbanks import FreeFB

# Define parameters for the filterbank
n_filters = 256
kernel_size = 128
stride = 64
sample_rate = 16000

# 1. Instantiate a filterbank (e.g., a fully learnable Free Filterbank)
fb = FreeFB(n_filters=n_filters, kernel_size=kernel_size, stride=stride, sample_rate=sample_rate)

# 2. Wrap it with an Encoder to get the time-frequency representation
encoder = Encoder(fb)

# 3. Create a dummy waveform (batch, channels, time)
waveform = torch.randn(1, 1, sample_rate * 4) # 4 seconds of audio

# 4. Encode the waveform into a spectrogram-like representation
spec_like = encoder(waveform)
print(f"Input waveform shape: {waveform.shape}")
print(f"Encoded spectrogram-like shape: {spec_like.shape}")

# 5. Instantiate a Decoder (can use the same filterbank or a different one)
decoder = Decoder(fb) # For reconstruction, often use the same filterbank

# 6. Decode the spectrogram-like representation back to waveform
out_waveform = decoder(spec_like)
print(f"Decoded waveform shape: {out_waveform.shape}")

view raw JSON →