Reputation: 53
Currently, I'm writing a python script, which should do the following:
When I try to run the script, I get the following error:
Traceback (most recent call last):
File "demo2.py", line 61, in <module>
F,T,S = scipy.signal.spectrogram(s_mono,rate,window,None,nOverlap,nFFT)
AttributeError: 'module' object has no attribute 'spectrogram'
Which is rather strange, because in my opinion my code should work fine. I've already checked for Syntax Errors and I also looked up in the official scipy documentation but I couldn't find any clue what could possible be wrong with it.
Here's a little snippet of my code:
import scipy
from scipy import signal
import scipy.io.wavfile as wav
#---------------------------------
# here's the rest of my code
F,T,S = scipy.signal.spectrogram(s_mono,rate,window,None,nOverlap,nFFT)
Additional Information: I'm working on a MacBook with MacOS 10.9.5
Upvotes: 1
Views: 4514
Reputation: 5279
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()
Upvotes: 0
Reputation: 288
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.
Upvotes: 1
Reputation: 1426
Please see if this works for you:
from scipy import signal
import numpy as np
import math
import matplotlib.pyplot as 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.).
Upvotes: 1