0
import os
import scipy.io
import scipy.io.wavfile
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
from scipy.signal import spectrogram, get_window

dataset_path = os.path.join(os.environ['HOME'], 'shared', 'data', 'assignment_1')
wavedata = os.path.join(dataset_path, 'example.wav')
   
fs, audio_buffer = scipy.io.wavfile.read(wavedata)

a = np.array(audio_buffer)


window = get_window('hann', frame_size)  # we will us a Hann window for the DFTs
    
freqs, times, spec = scipy.signal.spectrogram(audio_buffer, fs, window='hann')

plt.pcolormesh(times, freqs, spec)
np.log(spec)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.show()

I tried to make a spectrogram. The problem is that it is almost completely violet. How can I fix this?

enter image description here

  • 1
    You may want to plot the histogram of the spectrogram values, then you can see what the range of values present are. – Jon Nordby Oct 20 '20 at 08:15
  • 1
    Check out https://stackoverflow.com/questions/56456419/reproduce-sox-spectrogram-in-scipy/ – Warren Weckesser Oct 20 '20 at 11:50
  • 1
    What's the point of your line `np.log(spec)`? – tom10 Oct 20 '20 at 18:26
  • @tom10 actually that was an attempt to make logarithmic spectrogram which failed. but now I figured out – Natallia Yelavik Oct 21 '20 at 05:58
  • Great. Yes, the `np.log(spec)` seemed to be aiming at the right approach, but it was so just hanging there that I didn't know what you knew and didn't, and I therefore didn't quite see how to post an answer. In general, if you say things like, "the graph is all purple, and I thought `np.log(spec)` would fix that but it doesn't" it would be much easier to answer your questions. – tom10 Oct 21 '20 at 15:55

0 Answers0