Skip to content

Instantly share code, notes, and snippets.

@tuxmartin
Created December 4, 2015 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxmartin/bdaa26457fe7f5020c9e to your computer and use it in GitHub Desktop.
Save tuxmartin/bdaa26457fe7f5020c9e to your computer and use it in GitHub Desktop.
echo "test 123" | python googleTextToSpeech.py cs
#! /usr/bin/python
# https://github.com/tuxmartin/google-translator-text-to-speech
# !!! Pouze pro vyukove ucely! Na 99,9% porusuje licenci Googlu !!!
"""
Pouziti:
$ echo "test 123" | python googleTextToSpeech.py cs
$ echo "test 123" | python googleTextToSpeech.py en
Pokud neni zadany jazyk, pouzije se cestina.
Je nutne mit nainstalovany "wget" a "madplay" prehravac!
http://packages.ubuntu.com/search?keywords=madplay
"""
import sys
from subprocess import call
import urllib
try:
jazyk = sys.argv[1]
#print "Jazyk pro cteni = ", jazyk
except IndexError:
jazyk = "cs"
print "Nebyl zadan jazyk pro cteni! Pouzivam vychozi = ", jazyk
text = ""
for line in sys.stdin:
# print line
text += line
cti = urllib.quote_plus(text)
jmenoSouboru = text.rstrip('\n')
userAgent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0";
prikaz = "wget -U \"" + userAgent + "\" \"http://translate.google.com/translate_tts?ie=UTF-8&tl="+ jazyk +"&q=" + cti + "&total=1&idx=0&client=t\" -O \"" + jmenoSouboru + ".mp3\""
#prikaz = "wget -q -U \"" + userAgent + "\" \"http://translate.google.com/translate_tts?ie=UTF-8&tl="+ jazyk +"&q=" + cti + "&total=1&idx=0&client=t\" "
print prikaz
call(["/bin/sh", "-c", prikaz])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment