Python NumPy Convert FFT To File
Question: I was wondering if it's possible to get the frequencies present in a file with
NumPy, and then alter those frequencies and create a new WAV file from them? I
would like to do some filtering on a file, but I have yet to see a way to read
a WAV file into NumPy, filter it, and then _output the filtered version_. If
anyone could help, that would be great.


Answer: [SciPy](http://scipy.org/) provides functions for [doing
FFTs](http://docs.scipy.org/doc/scipy/reference/fftpack.html) on NumPy arrays,
and also provides functions for
[reading](http://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.read.html#scipy.io.wavfile.read)
and
[writing](http://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.write.html#scipy.io.wavfile.write)
them to WAV files. e.g.

    
    
    from scipy.io.wavfile import read, write
    from scipy.fftpack import rfft, irfft
    import np as numpy
    
    rate, input = read('input.wav')
    
    transformed = rfft(input) 
    
    filtered = function_that_does_the_filtering(transformed)
    output = irfft(filtered)
    
    write('output.wav', rate, output)
    

(`input`, `transformed` and `output` are all numpy arrays)

