question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The spectrogram computed by "torchaudio.compliance.kaldi.spectrogram" and "compute-spectrogram-feats" are different

See original GitHub issue

Dear 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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
yjw123456commented, Nov 27, 2019

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

0reactions
vincentqbcommented, Nov 27, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found