Skip to content

Instantly share code, notes, and snippets.

@cldotdev
Created January 5, 2014 08:05
Show Gist options
  • Select an option

  • Save cldotdev/8265669 to your computer and use it in GitHub Desktop.

Select an option

Save cldotdev/8265669 to your computer and use it in GitHub Desktop.
# Rollcode.com
import sys, subprocess, urllib
def getSpeech(phrase):
googleAPIurl = "http://translate.google.com/translate_tts?tl=en&"
param = {'q': phrase}
data = urllib.urlencode(param)
googleAPIurl += data # Append the parameters
return googleAPIurl
def raspberryTalk(text): # This will call mplayer and will play the sound
subprocess.call(["mplayer",getSpeech(text)], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if __name__ == "__main__":
raspberryTalk("Hello from Rollcode.com")
http://translate.google.com/translate_tts?tl=zh-TW&q=台北的天氣晴&ie=UTF-8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment