Read MP3 in Python 3 Read MP3 in Python 3 python python

Read MP3 in Python 3


You could use librosa:

import librosay, sr = librosa.load('your_file.mp3')

Further information: https://github.com/librosa/librosa


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.wavor$ 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.


Can be done with pydub:

import arrayfrom pydub import AudioSegmentfrom pydub.utils import get_array_typesound = AudioSegment.from_file(file=path_to_file)left = sound.split_to_mono()[0]bit_depth = left.sample_width * 8array_type = get_array_type(bit_depth)numeric_array = array.array(array_type, left._data)