I'm trying to read in a wav file to run an fft on it but I keep running into an error with scipy.
import matplotlib.pyplot as plt
from scipy.io import wavfile as wav
import scipy
from scipy.fftpack import fft
import numpy as np
rate, data = scipy.io.wavfile.read('a1.wav')
fft_out = fft(data)
#matplotlib inline
plt.plot(data, np.abs(fft_out))
plt.show()
print 'exit'
The error I'm running into is:
Traceback (most recent call last):
File "test.py", line 9, in <module>
rate, data = scipy.io.wavfile.read('a1.wav')
File "/usr/local/lib/python2.7/site-packages/scipy/io/wavfile.py", line 275, in read
return fs, data
UnboundLocalError: local variable 'data' referenced before assignment
I thought it might have been an anaconda error so I removed anaconda but I'm still running into this issue.
If there is a better way to read wav files so that I can run ffts on them, let me know! Thanks!
a1.wav.