Skip to content Skip to sidebar Skip to footer

Attributeerror: 'module' Object Has No Attribute 'spectrogram'

Currently, I'm writing a python script, which should do the following: read an audio file respectively a wav file via scipy.io.wavfile.read(). calculate the spectrogram of given w

Solution 1:

Since there's no signal.py, uninstall scipy and reinstall it without using pip. Get it from their website. Getting it with pip seems to almost always have problems.

Solution 2:

Please see if this works for you:

from scipy import signal
import numpy as np
import math
import matplotlib.pyplotas plt

t = np.arange(10000)
sig = np.sin(2. * math.pi * 1 / 1000. * t)
f, t, Sxx = signal.spectrogram(sig, 1.)
plt.pcolormesh(t, f, Sxx)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.show()

It works for me with python 2.7 and scipy 0.19.

If this works for you, then you are probably causing some weird namespace errors in your script (calling a variable signal, etc.).

Solution 3:

I also had an issue with this ... caused by my bad variable assignments.

This is how I read and process a wav file. Please note the wave file needs to have metadata stripped (I used ffmpeg to do this)

from scipy import signal
import numpy as np
import math
import matplotlib.pyplot as plt

import soundfile as sf
from matplotlib import pyplot as plt
datasignal, fs_rate= sf.read('40m_stripped.wav')
print(f"Data shape is {datasignal.shape}")
sig=datasignal[::,0]
print(f"Sig shape is {sig.shape}")
f, t, Sxx = signal.spectrogram(sig, fs_rate)
plt.pcolormesh(t, f, Sxx)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.show()

Post a Comment for "Attributeerror: 'module' Object Has No Attribute 'spectrogram'"