title: Read wav file into python
body: <p>I'm trying to read in a wav file to run an fft on it but I keep running into an error with scipy. </p>
  
  <pre><code>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'
  </code></pre>
  
  <p>The error I'm running into is:</p>
  
  <pre><code>Traceback (most recent call last):
      File "test.py", line 9, in &lt;module&gt;
          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
  </code></pre>
  
  <p>I thought it might have been an anaconda error so I removed anaconda but I'm still running into this issue.</p>
  
  <p>If there is a better way to read wav files so that I can run ffts on them, let me know! Thanks!</p>