title: How can I convert any random byte string to a playable mp3 file in python3.6?
body: <p>I have random bytes of data which I need to convert to mp3 format(although it might be noise). And I should be able to play the (noisy) mp3 file.</p>
  
  <pre><code>from pydub import AudioSegment
  from pydub.playback import play
  import io
  
  data=open("cipher.json","rb").read()
  recording = AudioSegment.from_file(io.BytesIO(data), format="mp3")
  recording.export('new.mp3', format='mp3') # for export 
  play(recording) # for play
  </code></pre>
  
  <p>Error is as follows:</p>
  
  <pre><code>Traceback (most recent call last):
    File "temp.py", line 17, in &lt;module&gt;
      recording = AudioSegment.from_file(io.BytesIO(data), format="mp3")
    File "/home/shreyas/.local/lib/python3.6/site-packages/pydub/audio_segment.py", line 704, in from_file
      p.returncode, p_err))
  pydub.exceptions.CouldntDecodeError: Decoding failed. ffmpeg returned error code: 1
  
  Output from ffmpeg/avlib:
  
  b"ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers\n  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)\n  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared\n  libavutil      55. 78.100 / 55. 78.100\n  libavcodec     57.107.100 / 57.107.100\n  libavformat    57. 83.100 / 57. 83.100\n  libavdevice    57. 10.100 / 57. 10.100\n  libavfilter     6.107.100 /  6.107.100\n  libavresample   3.  7.  0 /  3.  7.  0\n  libswscale      4.  8.100 /  4.  8.100\n  libswresample   2.  9.100 /  2.  9.100\n  libpostproc    54.  7.100 / 54.  7.100\n[mp3 @ 0x564e0e6d4fa0] Header missing\n[mp3 @ 0x564e0e6d3900] decoding for stream 0 failed\n[mp3 @ 0x564e0e6d3900] Could not find codec parameters for stream 0 (Audio: mp3, 0 channels, s16p): unspecified frame size\nConsider increasing the value for the 'analyzeduration' and 'probesize' options\nInput #0, mp3, from 'pipe:':\n  Duration: N/A, start: 0.000000, bitrate: N/A\n    Stream #0:0: Audio: mp3, 0 channels, s16p\nStream mapping:\n  Stream #0:0 -&gt; #0:0 (mp3 (native) -&gt; pcm_s16le (native))\n[mp3 @ 0x564e0e6d72e0] Header missing\nError while decoding stream #0:0: Invalid data found when processing input\nFinishing stream 0:0 without any data written to it.\n[abuffer @ 0x564e0e6dba80] Value inf for parameter 'time_base' out of range [0 - 2.14748e+09]\n    Last message repeated 3 times\n[abuffer @ 0x564e0e6dba80] Error setting option time_base to value 1/0.\n[graph_0_in_0_0 @ 0x564e0e6db980] Error applying options to the filter.\nError configuring filter graph\nConversion failed!\n"
  </code></pre>