What is the easiest way to read wav-files using Python [summary]?

后端 未结 8 697
夕颜
夕颜 2020-12-09 13:13

I want to use Python to access a wav-file and write its content in a form which allows me to analyze it (let\'s say arrays).

  1. I heard that \"audiolab\" is a sui
8条回答
  •  旧时难觅i
    2020-12-09 13:41

    You can also use the wave module along with the numpy.fromstring() function to convert it to an array

    import wave
    import numpy
    
    fp = wave.open('test.wav')
    nchan = fp.getnchannels()
    N = fp.getnframes()
    dstr = fp.readframes(N*nchan)
    data = numpy.fromstring(dstr, numpy.int16)
    data = numpy.reshape(data, (-1,nchan))
    

提交回复
热议问题