I have a MelSpectrogram
generated from:
eval_seq_specgram = torchaudio.transforms.MelSpectrogram(sample_rate=sample_rate, n_fft=256)(eval_audio_data).transpose(1, 2)
So eval_seq_specgram
now has a size
of torch.Size([1, 128, 499])
, where 499 is the number of timesteps and 128 is the n_mels
.
I'm trying to invert it, so I'm trying to use GriffinLim
, but before doing that, I think I need to invert the melscale
, so I have:
inverse_mel_pred = torchaudio.transforms.InverseMelScale(sample_rate=sample_rate, n_stft=256)(eval_seq_specgram)
inverse_mel_pred
has a size
of torch.Size([1, 256, 499])
Then I'm trying to use GriffinLim
:
pred_audio = torchaudio.transforms.GriffinLim(n_fft=256)(inverse_mel_pred)
but I get an error:
Traceback (most recent call last):
File "evaluate_spect.py", line 63, in <module>
main()
File "evaluate_spect.py", line 51, in main
pred_audio = torchaudio.transforms.GriffinLim(n_fft=256)(inverse_mel_pred)
File "/home/shamoon/.local/share/virtualenvs/speech-reconstruction-7HMT9fTW/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/shamoon/.local/share/virtualenvs/speech-reconstruction-7HMT9fTW/lib/python3.8/site-packages/torchaudio/transforms.py", line 169, in forward
return F.griffinlim(specgram, self.window, self.n_fft, self.hop_length, self.win_length, self.power,
File "/home/shamoon/.local/share/virtualenvs/speech-reconstruction-7HMT9fTW/lib/python3.8/site-packages/torchaudio/functional.py", line 179, in griffinlim
inverse = torch.istft(specgram * angles,
RuntimeError: The size of tensor a (256) must match the size of tensor b (129) at non-singleton dimension 1
Not sure what I'm doing wrong or how to resolve this.
torchaudio.info function fetches metadata of audio. You can provide a path-like object or file-like object. bits_per_sample can be 0 for formats with compression and/or variable bit rate (such as mp3).
Torchaudio is a library for audio and signal processing with PyTorch. It provides I/O, signal and data processing functions, datasets, model implementations and application components.
What is Mel Spectrogram? Mel spectrogram is a spectrogram that is converted to a Mel scale. Then, what is the spectrogram and The Mel Scale? A spectrogram is a visualization of the frequency spectrum of a signal, where the frequency spectrum of a signal is the frequency range that is contained by the signal.
By looking at the documentation and by doing a quick test on colab it seems that:
As a side note, I don't understand why you need the transpose call, since according to the doc and my tests
waveform, sample_rate = torchaudio.load('test.wav')
mel_specgram = transforms.MelSpectrogram(sample_rate)(waveform) # (channel, n_mels, time)
already returns a (channel, n_mels, time) tensor and InverseMelScale wants a tensor of shape (…, n_mels, time)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With