title: MP3 to FLAC for Google's Speech API
body: <p>I'm trying to find a simple way to send an MP3 to Google for speech recognition. Currently, I'm using a sub process to call SoX which converts it to a WAV. Then, using <a href="https://pypi.python.org/pypi/SpeechRecognition/" rel="nofollow" title="SpeechRecognition">SpeechRecognition</a>, it converts it again to FLAC. Ideally, I'd like a more portable (not OS specific) way to decode the MP3 and send it with no intermediate file saving and the like.</p>
  
  <p>Here's what I have currently:</p>
  
  <pre><code>import speech_recognition as sr
  import subprocess
  import requests
  
  audio = requests.get('http://somesite.com/some.mp3')
  
  with open('/tmp/audio.mp3', 'wb') as file:
      file.write(audio.content)
  
  subprocess.run(['sox', '/tmp/audio.mp3', '/tmp/audio.wav'])
  
  r = sr.Recognizer()
  with sr.WavFile('/tmp/audio.wav') as source:
      audio = r.record(source)
  
  result = r.recognize_google(audio)
  del r
  </code></pre>
  
  <p>I've tried directly using the FLAC binaries included in <a href="https://pypi.python.org/pypi/SpeechRecognition/" rel="nofollow" title="SpeechRecognition">SpeechRecognition</a>, but the output was just static. I'm not too keen on distributing binaries on Git, but I will if that is the only way.</p>
  
  <p>Some important links:</p>
  
  <p><a href="https://github.com/Uberi/speech_recognition/blob/master/speech_recognition/__init__.py#L379" rel="nofollow">SR's code for speech recognition</a></p>
  
  <p><a href="https://github.com/Uberi/speech_recognition/blob/master/speech_recognition/__init__.py#L162" rel="nofollow">SR's code for WAV to FLAC</a></p>
  
  <p><strong>Edit</strong></p>
  
  <p>I'm considering distributing SoX in a way like the FLAC binaries were, one for each OS, if SoX's license allows it...</p>
  
  <p>Second thought, software licenses are confusing and I don't want to mess with that.</p>