Created
January 5, 2014 08:05
-
-
Save cldotdev/8265669 to your computer and use it in GitHub Desktop.
http://rollcode.com/talking-raspberry-pi-using-python/
Google translation API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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