title: Python: performing FFT on music file
body: <p>I am trying to perform a FFT on a song (audio file in wav format, about 3 minutes long) which I created as follows, just in case it is relevant.</p>
  
  <pre><code>ffmpeg -i "$1" -vn -ab 128k -ar 44100 -y -ac 1 "${1%.webm}.wav"
  </code></pre>
  
  <p>Where <code>$1</code> is the name of a webm file.</p>
  
  <p>This is the code which is supposed to display a FFT of the given file:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  # presume file already converted to wav.
  file = os.path.join(temp_folder, file_name)
  
  rate, aud_data = scipy.io.wavfile.read(file)
  
  # wav file is mono.
  channel_1 = aud_data[:]
  
  fourier = np.fft.fft(channel_1)
  
  plt.figure(1)
  plt.plot(fourier)
  plt.xlabel('n')
  plt.ylabel('amplitude')
  plt.show()
  </code></pre>
  
  <p>The problem is, it takes for ever. It takes so long that I cannot even show the output, since I've had plenty of time to research and write this post and it still has not finished.</p>
  
  <p>I presume that the file is too long, since</p>
  
  <pre><code>print (aud_data.shape)
  </code></pre>
  
  <p>outputs <code>(9218368,)</code>, but this looks like a real world problem, so I hope there is a way to obtain an FFT of an audio file somehow.</p>
  
  <p>What am I doing wrong? Thank you.</p>
  
  <p><strong>edit</strong></p>
  
  <p>A better formulation of the question would be: is the FFT of any good in music processing? For example similarity of 2 pieces.</p>
  
  <p>As pointed out in the comments, my plain approach is way too slow.</p>
  
  <p>Thank you. </p>