title: Extracting frequencies from a wav file python
body: <p>I am familiar with python but new to numpy, so please pardon me if I am wrong.</p>
  
  <p>I am trying to read a .wav file having multiple frequencies (separated by silence). So far I've been able to read the values and find the various parts in the file where there is a sound. Then, I am trying to find the Discrete Cosine Transform and calculate the frequencies from it (ref: <a href="https://stackoverflow.com/questions/3694918/how-to-extract-frequency-associated-with-fft-values-in-python">how to extract frequency associated with fft values in python</a>)</p>
  
  <p>However, I'm getting an error:</p>
  
  <blockquote>
    <p>index 46392 is out of bounds for axis 0 with size 25</p>
  </blockquote>
  
  <p>Here's my code:</p>
  
  <pre><code>import wave
  import struct
  import numpy as np
  
  def isSilence(windowPosition):
      sumVal = sum( [ x*x for x in sound[windowPosition:windowPosition+windowSize+1] ] )
      avg = sumVal/(windowSize)
      if avg &lt;= 0.0001:
          return True
      else:
          return False
  
  #read from wav file
  sound_file = wave.open('test.wav', 'r')
  file_length = sound_file.getnframes()
  data = sound_file.readframes(file_length)
  sound_file.close()
  #data = struct.unpack("&lt;h", data)
  data = struct.unpack('{n}h'.format(n=file_length), data)
  sound = np.array(data)
  #sound is now a list of values
  
  #detect silence and notes
  i=0
  windowSize = 2205
  windowPosition = 0
  listOfLists = []
  listOfLists.append([])
  maxVal = len(sound) - windowSize
  while True:
      if windowPosition &gt;= maxVal:
          break
      if not isSilence(windowPosition):
          while not isSilence(windowPosition):
              listOfLists[i].append(sound[windowPosition:windowPosition+ windowSize+1])
              windowPosition += windowSize
          listOfLists.append([]) #empty list
          i += 1
      windowPosition += windowSize
  
  frequencies = []
  #Calculating the frequency of each detected note by using DFT
  for signal in listOfLists:
      if not signal:
          break
      w = np.fft.fft(signal)
      freqs = np.fft.fftfreq(len(w))
      l = len(signal)
  
      #imax = index of first peak in w
      imax = np.argmax(np.abs(w))
      fs = freqs[imax]
  
      freq = imax*fs/l
      frequencies.append(freq)
  
  print frequencies
  </code></pre>
  
  <p>Edit: Here is the traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "final.py", line 61, in &lt;module&gt;
      fs = freqs[imax]
  IndexError: index 46392 is out of bounds for axis 0 with size 21
  </code></pre>