The spectrogram computed by "torchaudio.compliance.kaldi.spectrogram" and "compute-spectrogram-feats" are different
See original GitHub issueDear Sir or Madam,
I compared the spectrogram generated by “torchaudio.compliance.kaldi.spectrogram” and “compute-spectrogram-feats” using default settings, however the outputs are different.
# The code for torchaudio is:
wav, sample_rate = torchaudio.load('wav/1.wav')
spectrum=torchaudio.compliance.kaldi.spectrogram(wav, blackman_coeff=0.42, channel=-1, dither=1.0, energy_floor=0.0, frame_length=25.0, frame_shift=10.0, min_duration=0.0, preemphasis_coefficient=0.97, raw_energy=True, remove_dc_offset=True, round_to_power_of_two=True, sample_frequency=16000.0, snip_edges=True, subtract_mean=False, window_type='povey')
# Kaldi is:
compute-spectrogram-feats --blackman_coeff=0.42 --channel=-1 --dither=1.0 --energy_floor=0.0 --frame_length=25.0 --frame_shift=10.0 --min_duration=0.0 --preemphasis_coefficient=0.97 --raw_energy=True --remove_dc_offset=True --round_to_power_of_two=True --sample_frequency=16000.0 --snip_edges=True --subtract_mean=False --window_type='povey' scp:wav.scp ark,t,scp:1_stft.ark,1_stft.scp
Can you give me some clue of it?
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
torchaudio.compliance.kaldi.spectrogram - PyTorch
Create a spectrogram from a raw audio signal. This matches the input/output of Kaldi's compute-spectrogram-feats. Parameters:.
Read more >torchaudio.compliance.kaldi
Create a spectrogram from a raw audio signal. This matches the input/output of Kaldi's compute-spectrogram-feats. Parameters: waveform (Tensor) – ...
Read more >MFCC and Mel Spectrograms (.NET, librosa, kaldi, torchaudio)
Playground - https://ar1st0crat.github.io/NWaves.PlaygroundDemo apps - https://github.com/ar1st0crat/NWaves.
Read more >Spectrograms Generated Using Librosa Don't Look Consistent ...
librosa.feature.melspectrogram Compute a melscaled spectrogram. ... New Features [torchaudio.compliance.kaldi.spectrogram]https://pytorch.org/audio/ ...
Read more >How to classify sounds using Pytorch | Analytics Vidhya
Change the waveform to Spectrogram, Mel Spectrogram or, MFCC. ... mfcc = torchaudio.compliance.kaldi.mfcc(waveform, **params).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, vincentqb,
Sorry for the late reply. @vincentqb @wuqiangch
I found the answer of this problem.
The waveform loaded by torchaudio is transformed into float type. While kaldi directly uses integers to calculate the spectrogram.
So if I do: wav, sample_rate = torchaudio.load(‘tmp.wav’) wav = wav*2**15 Then the outputs will be exactly the same.
The whole code in kaldi is: compute-spectrogram-feats --blackman_coeff=0.42 --channel=-1 --dither=1.0 --energy_floor=0.0 --frame_length=25.0 --frame_shift=10.0 --min_duration=0.0 --preemphasis_coefficient=0.97 --raw_energy=True --remove_dc_offset=True --round_to_power_of_two=True --sample_frequency=16000.0 --snip_edges=True --subtract_mean=False --window_type=‘povey’ scp:wav.scp ark,t,scp:1_stft.ark,1_stft.scp
In the wav.scp is: utt-id tmp.wav
Glad this answers your question. Yes, torchaudio normalizes waveforms to [-1, 1]. I will close this issue, but please feel free to reopen or create a new one.