title: Play the contents of a sound retrieved from an url?
body: <p>I am retrieving the sound from:</p>
  
  <blockquote>
    <p><a href="http://translate.google.com/translate_tts" rel="nofollow">http://translate.google.com/translate_tts</a></p>
  </blockquote>
  
  <p>and writing it to a WAV file, when i double-click the file the sound plays ok, but when i use the WAVE module from python to open it, it gives me this error:</p>
  
  <blockquote>
    <p>wave.Error: file does not start with RIFF id</p>
  </blockquote>
  
  <p>I want to know if there is a way for openning this file, or if it is possible to play the sound without writing it before.</p>
  
  <p>Here is the relevant code:</p>
  
  <pre><code>url = "http://translate.google.com/translate_tts?tl=%s&amp;q=%s" % (lang, text)
  hrs = {"User-Agent":
         "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7"}
  
  request = urllib.request.Request(url, headers = hrs)
  page = urllib.request.urlopen(request)
  
  fname = "Play"+str(int(time.time()))+".wav"
  file = open(fname, 'wb')
  file.write(page.read())
  file.close()
  </code></pre>
  
  <p>And the code that reads this file is:</p>
  
  <pre><code>INPUT_FRAMES_PER_BLOCK = 1024
  
  wf = wave.open(fname, 'r')
  
  pa = pyaudio.PyAudio()
  
  stream = pa.open(format=pa.get_format_from_width(wf.getsampwidth()),
                   channels=wf.getnchannels(),
                   rate=wf.getframerate(),
                   output=True)
  
  data = wf.readframes(INPUT_FRAMES_PER_BLOCK)
  
  while data != '':
      stream.write(data)
      data = wf.readframes(INPUT_FRAMES_PER_BLOCK)
  
  stream.stop_stream()
  stream.close()
  
  pa.terminate()
  </code></pre>
  
  <p>Thanks in advance!
  I am using Python 3 BTW.</p>