-
-
Save AndersonFirmino/f1f872f43c68bac535d0e9b7d5f6ceb4 to your computer and use it in GitHub Desktop.
Google Text To Speech in Python (TTS), more info at http://alexsleat.co.uk/2011/11/14/python-making-use-of-googles-text-to-speech-translation-tool/
This file contains 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
#!/usr/bin/python | |
import sys #for cmd line argv | |
#take command line args as the input string | |
input_string = sys.argv | |
#remove the program name from the argv list | |
input_string.pop(0) | |
#convert to google friendly url (with + replacing spaces) | |
tts_string = '+'.join(input_string) | |
print tts_string |
This file contains 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
#!/usr/bin/python | |
import time #for delay | |
import pygst #for playing mp3 stream | |
import gst # " " | |
#Play an .mp3 file from the internet | |
music_stream_uri = 'http://www.sample-url.com/file.mp3' | |
player = gst.element_factory_make("playbin", "player") | |
player.set_property('uri', music_stream_uri) | |
player.set_state(gst.STATE_PLAYING) | |
#requires a delay, if the py process closes before the mp3 has finished it will be cut off. | |
time.sleep(12) |
This file contains 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
#!/usr/bin/python | |
import sys #for cmd line argv | |
import time #for delay | |
import pygst #for playing mp3 stream | |
import gst # " " | |
#take command line args as the input string | |
input_string = sys.argv | |
#remove the program name from the argv list | |
input_string.pop(0) | |
#convert to google friendly url (with + replacing spaces) | |
tts_string = '+'.join(input_string) | |
print tts_string | |
#use string in combination with the translate url as the stream to be played | |
music_stream_uri = 'http://translate.google.com/translate_tts?q=' + tts_string | |
player = gst.element_factory_make("playbin", "player") | |
player.set_property('uri', music_stream_uri) | |
player.set_state(gst.STATE_PLAYING) | |
#requires a delay, if the py process closes before the mp3 has finished it will be cut off. | |
time.sleep(12) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment