Read MP3 in Python 3

前端 未结 7 1251
面向向阳花
面向向阳花 2020-12-15 03:46

What I want to do is simply

mp3 = read_mp3(mp3_filename)
audio_left = mp3.audio_channels[0]

where audio_left will contain raw PCM audio dat

7条回答
  •  情书的邮戳
    2020-12-15 04:20

    To make it easier I'd convert with some tools mp3 to wav, either:

    $ ffmpeg -i foo.mp3 -vn -acodec pcm_s16le -ac 1 -ar 44100 -f wav foo.wav
    or
    $ mpg123 -w foo.wav foo.mp3
    

    Then read the WAV with one of the python WAV libraries. I'd recommend PySoundFile because it works with most generated WAV correctly and installed without issue (as opposed to scikits.audiolab).

    Note: Even though scipy.io.wavfile.read() gave me a "WavFileWarning: Unfamiliar format bytes" warning, it also loaded the file properly.

提交回复
热议问题