Search code examples
pythonnumpywav

Python: write a wav file into numpy float array


ifile = wave.open("input.wav")

how can I write this file into a numpy float array now?


Solution

  • >>> from scipy.io.wavfile import read
    >>> a = read("adios.wav")
    >>> numpy.array(a[1],dtype=float)
    array([ 128.,  128.,  128., ...,  128.,  128.,  128.])
    

    Typically it would be bytes which are then ints... here we just convert it to float type.

    You can read about read here: https://docs.scipy.org/doc/scipy/reference/tutorial/io.html#module-scipy.io.wavfile