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

后端 未结 8 662
夕颜
夕颜 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条回答
  • 2020-12-09 13:46

    pydub provides an even easier solution without any dependencies needing to be installed (for wav files). I'm currently using this method in production without any issues.

    from pydub import AudioSegment
    awesome_song = AudioSegment.from_wav('awesome_song.wav')
    print('Duration in seconds is {}'.format(awesome_song.duration_seconds))
    
    0 讨论(0)
  • 2020-12-09 14:00

    This is good enough for me

    import numpy as np
    x = np.fromfile(open('song.wav'),np.int16)[24:]
    

    It ignores the first 24 values, because that's not audio, it the header.

    Also, if the file was stereo, your channels will have alternating indexes, So I usually just reduce it to mono with Audacity first.

    0 讨论(0)
提交回复
热议问题