How to extract the raw data from a mp3 file using python?

zhangyangyu picture zhangyangyu · May 19, 2013 · Viewed 23.3k times · Source

I have got homework regarding audio data analysis using Python. I wonder is there any good module for me to use to extract the raw data from a mp3 file. I mean the raw data, not the metadata, id3 tags.

I know how to use the wave module to process .wav files. I can readframes to get the raw data. But I don't know how to do with mp3. I have searched a lot on google and stackoverflow and find eyeD3. But unfortunately the documentation is rather frustrating and now the version is 0.7.1, different from most examples I can find on the Internet.

Is there any good module that can extract raw data from a mp3? If there is any good documentation for eyeD3, it is also good.

Answer

Jiaaro picture Jiaaro · Sep 16, 2013

If I understand your question, you can try using pydub (a library I wrote) to get the audio data like so:

from pydub import AudioSegment

sound = AudioSegment.from_mp3("test.mp3")

# sound._data is a bytestring
raw_data = sound._data