Is there a way to read/write a MP3 audio file into/from a numpy
array with a similar API to scipy.io.wavfile.read and scipy.io.wavfile.write:
sr, x = wavfile.read('test.wav')
wavfile.write('test2.wav', sr, x)
?
Note: pydub
's AudioSegment
object doesn't give direct access to a numpy array.
PS: I have already read Importing sound files into Python as NumPy arrays (alternatives to audiolab), tried all the answers, including those which requires to Popen
ffmpeg and read the content from stdout pipe, etc. I have also read Trying to convert an mp3 file to a Numpy Array, and ffmpeg just hangs, etc., and tried the main answers, but there was no simple solution. After spending hours on this, I'm posting it here with "Answer your own question – share your knowledge, Q&A-style". I have also read How to create a numpy array from a pydub AudioSegment? but this does not easily cover the multi channel case, etc.