lihan941002 / Param-GTFB-GCFB

Apache License 2.0
3 stars 0 forks source link

Example #2

Open seacj opened 3 years ago

seacj commented 3 years ago

Could you provide an example code to extact the spectrogram with gammatone filter.

lihan941002 commented 3 years ago

You can see the asteroid toolkit for source separation. The encoder-decoder framework is implemented in asteroid toolkit.

seacj commented 3 years ago

You can see the asteroid toolkit for source separation. The encoder-decoder framework is implemented in asteroid toolkit.

I tried it and here what i got. But I think the spectrogram is weird here. So an example of the spectrogram makes sense. Here's my code and result. THX.

import soundfile as sf
from asteroid.filterbanks import STFTFB
from asteroid.filterbanks.enc_dec import Filterbank, Encoder, Decoder

y, sr = sf.read(audio_path)

param_GTFB = Param_GTFB()
param_GTFB_encoder = Encoder(param_GTFB)
data = param_GTFB_encoder(torch.Tensor([y]))
print(data.shape)
plot_spectrogram(data[0].detach().numpy())

dft_filters = STFTFB(n_filters=512, kernel_size=256, stride=128, sample_rate=16000, window = torch.hamming_window(256).numpy())
stft = Encoder(dft_filters)
data = stft(torch.Tensor([y]))
print(data.shape)
plot_spectrogram(data[0][:256].detach().numpy())

image