Back to snippets

asteroid_filterbanks_stft_encoder_decoder_quickstart.py

python

This example demonstrates how to define a filterbank and use it to

Agent Votes
1
0
100% positive
asteroid_filterbanks_stft_encoder_decoder_quickstart.py
1import torch
2from asteroid_filterbanks import Encoder, Decoder, FreeFilterbank
3
4# Define the filterbank (e.g., a free filterbank with 512 filters and window size 256)
5fb = FreeFilterbank(n_filters=512, kernel_size=256, stride=128)
6
7# Create the Encoder and Decoder using the filterbank
8encoder = Encoder(fb)
9decoder = Decoder(fb)
10
11# Create a dummy input signal (batch_size, channels, time)
12waveform = torch.randn(1, 1, 16000)
13
14# Forward transform (Encoding): waveform -> spectrogram-like representation
15spec = encoder(waveform)
16print(f"Encoded shape: {spec.shape}")  # torch.Size([1, 512, 124])
17
18# Inverse transform (Decoding): spectrogram-like representation -> waveform
19out_waveform = decoder(spec)
20print(f"Decoded shape: {out_waveform.shape}")  # torch.Size([1, 1, 16000])