blob: 79a0ae08aed75b66b569d99a9352113e87b8ff00 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#!/usr/bin/python
import os
import os.path
import string
import urllib2
from threads.TInterpreterPlaySound import TInterpreterPlaySound
def __internetOn():
try:
urllib2.urlopen('http://www.google.com',timeout=1)
return True
except urllib2.URLError as err:
pass
return False
def intentar(projectName, texto):
texto = texto.split(" ")
texto = string.join(texto, "+")
destino = os.path.join("proyectos", projectName, texto + ".mp3")
if os.path.exists(destino): #ya lo tengo, lo reproduzco
t = TInterpreterPlaySound([destino, ])
t.start()
return True
else: #no lo tengo
if __internetOn(): #hay internet
os.system("wget -q -U Mozilla -O \"" + destino + "\" \"http://translate.google.com/translate_tts?ie=UTF-8&tl=es&q=" + texto + "\"")
t = TInterpreterPlaySound([destino, ])
t.start()
return True
else: #no hay internet y no lo tengo
return False
|