You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to figure out the correspondence between librosa and torchlibrosa for the spectrogram extraction.
As stated in the description, Spectrogram method of torchlibrosa corresponds to the stft method of librosa.
I created the following script to check if this true but I get different results:
importnumpyasnpimportlibrosaimporttorchlibrosaastlimporttorchif__name__=="__main__":
# Sample audio of 8KHzaudio=np.random.randn(1, 8_000).astype(np.float32)
# Extract Spectrogram Amplitude with LibrosaSpecl=np.squeeze(np.abs(librosa.stft(y=audio, n_fft=1024, hop_length=256)))
# Shape: (Freq bins x Time bins)print(f"Librosa spec shape: {Specl.shape}")
# Extract Spectrogram Amplitude with TLspec_extractor=tl.Spectrogram(n_fft=1024, hop_length=256, power=1)
Spectl=torch.squeeze(spec_extractor(torch.from_numpy(audio))).T# Shape (Freq bins x Time bins)print(f"TorchLibrosa spec shape: {Spectl.shape}")
# Compareprint("\n\nLibrosa Spectrogram\n", Specl, "\n\n\n", "Torch Librosa Spectrogram\n", Spectl)
Specl=torch.from_numpy(Specl)
print(f"\nL infty norm of difference: {torch.abs(Specl-Spectl).max()}")
When I execute the above script with python librosa_comparison.py I get the following output:
Hello everyone and good job for this library.
I am trying to figure out the correspondence between librosa and torchlibrosa for the spectrogram extraction.
As stated in the description,
Spectrogram
method of torchlibrosa corresponds to thestft
method of librosa.I created the following script to check if this true but I get different results:
When I execute the above script with
python librosa_comparison.py
I get the following output:Is anything that I am doing wrong? What's the relation between
Spectrogram
method of torchlibrosa andstft
of librosa.Thanks in advance!
The text was updated successfully, but these errors were encountered: