title: How to read a MP3 audio file into a numpy array / save a numpy array to MP3?
body: <p><strong>Is there a way to read/write a MP3 audio file into/from a <code>numpy</code> array with a similar API to <a href="https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.io.wavfile.read.html" rel="noreferrer">scipy.io.wavfile.read</a> and <a href="https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.io.wavfile.write.html" rel="noreferrer">scipy.io.wavfile.write</a>:</strong></p>
  
  <pre><code>sr, x = wavfile.read('test.wav')
  wavfile.write('test2.wav', sr, x)
  </code></pre>
  
  <p><strong>?</strong></p>
  
  <p>Note: <code>pydub</code>'s <code>AudioSegment</code> object doesn't give direct access to a numpy array.</p>
  
  <p><sup>PS: I have already read <a href="https://stackoverflow.com/questions/2356779/importing-sound-files-into-python-as-numpy-arrays-alternatives-to-audiolab">Importing sound files into Python as NumPy arrays (alternatives to audiolab)</a>, tried all the answers, including those which requires to <code>Popen</code> ffmpeg and read the content from stdout pipe, etc. I have also read <a href="https://stackoverflow.com/questions/38192663/trying-to-convert-an-mp3-file-to-a-numpy-array-and-ffmpeg-just-hangs">Trying to convert an mp3 file to a Numpy Array, and ffmpeg just hangs</a>, 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&amp;A-style". I have also read <a href="https://stackoverflow.com/questions/38015319/how-to-create-a-numpy-array-from-a-pydub-audiosegment">How to create a numpy array from a pydub AudioSegment?</a> but this does not easily cover the multi channel case, etc.</sup></p>