Commit e279ce29 authored by nextime's avatar nextime

Update text2speech to use responsivevoice.org

parent cba886b0
...@@ -194,7 +194,8 @@ ...@@ -194,7 +194,8 @@
audio.setAttribute('id' , 'playTTS_audio'); audio.setAttribute('id' , 'playTTS_audio');
} }
// XXX BUG: webkit based browsers seems to not work with https:// in <audio>, so, we fix this to http // XXX BUG: webkit based browsers seems to not work with https:// in <audio>, so, we fix this to http
audio.setAttribute('src', 'http://translate.google.com/translate_tts?tl='+lang+'&q=' + encodeURIComponent(text)); //audio.setAttribute('src', 'http://translate.google.com/translate_tts?tl='+lang+'&q=' + encodeURIComponent(text));
audio.setAttribute('src', 'http://code.responsivevoice.org/getvoice.php?tl='+lang+'&t=' + encodeURIComponent(text));
audio.load(); audio.load();
audio.play(); audio.play();
return audio; return audio;
......
a:2:{s:9:"timestamp";i:1395332244;s:12:"translations";a:18:{s:4:"home";s:4:"home";s:5:"blind";s:10:"tapparelle";s:8:"cancello";s:8:"cancelli";s:5:"clima";s:5:"clima";s:4:"door";s:5:"porte";s:3:"led";s:3:"led";s:5:"light";s:4:"luci";s:7:"scenari";s:7:"scenari";s:6:"socket";s:5:"prese";s:6:"valvle";s:7:"valvole";s:6:"sensor";s:7:"sensori";s:6:"camera";s:10:"telecamere";s:6:"window";s:8:"finestre";s:4:"user";s:4:"user";s:4:"none";s:15:"Nessuna Sezione";s:5:"phone";s:8:"telefono";s:5:"index";s:4:"Home";s:4:"gate";s:8:"cancelli";}} a:2:{s:9:"timestamp";i:1441816319;s:12:"translations";a:18:{s:4:"home";s:4:"home";s:5:"blind";s:10:"tapparelle";s:8:"cancello";s:8:"cancelli";s:5:"clima";s:5:"clima";s:4:"door";s:5:"porte";s:3:"led";s:3:"led";s:5:"light";s:4:"luci";s:7:"scenari";s:7:"scenari";s:6:"socket";s:5:"prese";s:6:"valvle";s:7:"valvole";s:6:"sensor";s:7:"sensori";s:6:"camera";s:10:"telecamere";s:6:"window";s:8:"finestre";s:4:"user";s:4:"user";s:4:"none";s:26:"verifica_comandi_controlli";s:5:"phone";s:8:"telefono";s:5:"index";s:4:"Home";s:4:"gate";s:8:"cancelli";}}
\ No newline at end of file \ No newline at end of file
...@@ -28,7 +28,10 @@ from twisted.protocols import basic ...@@ -28,7 +28,10 @@ from twisted.protocols import basic
import socket, logging, time import socket, logging, time
from starpy import error, fastagi from starpy import error, fastagi
import os, logging, time, sys import os, logging, time, sys
from domotika.clouds.google import tts, speech #from domotika.clouds.google import tts, speech
from domotika.clouds.google import tts as googletts
from domotika.clouds.google import speech
from domotika.clouds.responsivevoice import tts
import tempfile import tempfile
from txscheduling.cron import CronSchedule, parseCronLine from txscheduling.cron import CronSchedule, parseCronLine
from dmlib.utils import genutils from dmlib.utils import genutils
...@@ -290,7 +293,11 @@ class DMSayText(BaseCheck): ...@@ -290,7 +293,11 @@ class DMSayText(BaseCheck):
return self.play(saytext, replay, return self.play(saytext, replay,
".".join(playfile.split(".")[:-1]), ".".join(playfile.split(".")[-1:])) ".".join(playfile.split(".")[:-1]), ".".join(playfile.split(".")[-1:]))
if engine=='google': if engine=='google':
gtts=tts.TTS(saytext, tlang) gtts=googletts.TTS(saytext, tlang)
playfile=tempfile.mktemp(prefix="googletts-", suffix=".sln")
return gtts.convertAudioFile(fdst=playfile).addCallback(_converted, playfile)
elif engine=="responsivevoice":
gtts=tts.TTS(saytext, tlang)
playfile=tempfile.mktemp(prefix="googletts-", suffix=".sln") playfile=tempfile.mktemp(prefix="googletts-", suffix=".sln")
return gtts.convertAudioFile(fdst=playfile).addCallback(_converted, playfile) return gtts.convertAudioFile(fdst=playfile).addCallback(_converted, playfile)
else: else:
......
...@@ -29,7 +29,7 @@ from twisted.internet import defer ...@@ -29,7 +29,7 @@ from twisted.internet import defer
from twisted.internet import utils as twutils from twisted.internet import utils as twutils
import os import os
TTSURI="http://translate.google.com/translate_tts" TTSURI="https://translate.google.com/translate_tts"
def getSampleRate(fname): def getSampleRate(fname):
ext=fname.split(".")[-1:] ext=fname.split(".")[-1:]
...@@ -42,13 +42,14 @@ def getSampleRate(fname): ...@@ -42,13 +42,14 @@ def getSampleRate(fname):
class TTS(object): class TTS(object):
agent="Mozilla/5.0 (X11; Linux; rv:8.0) Gecko/20100101" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.6 Safari/537.36"
def __init__(self, text, lang="it"): def __init__(self, text, lang="it"):
self.text = urllib.quote(text.encode('utf8', 'ignore')) self.text = urllib.quote(text.encode('utf8', 'ignore'))
self.audiourl = TTSURI+"?tl="+lang+"&q="+self.text self.audiourl = TTSURI+"?tl="+lang+"&q="+self.text
def getAudio(self): def getAudio(self):
print "get", self.audiourl
return web.getPage(self.audiourl, agent=self.agent) return web.getPage(self.audiourl, agent=self.agent)
def saveAudioFile(self, nfile=False, raw=True): def saveAudioFile(self, nfile=False, raw=True):
...@@ -56,6 +57,7 @@ class TTS(object): ...@@ -56,6 +57,7 @@ class TTS(object):
nfile=tempfile.mktemp(prefix="googletts-", suffix=".mp3") nfile=tempfile.mktemp(prefix="googletts-", suffix=".mp3")
def saveFile(fcont): def saveFile(fcont):
print "tornato"
f=open(nfile, "w") f=open(nfile, "w")
f.write(fcont) f.write(fcont)
f.close() f.close()
......
...@@ -15,4 +15,5 @@ if [ "$2" != "en" ] && [ "$2" != "it" ] ; then ...@@ -15,4 +15,5 @@ if [ "$2" != "en" ] && [ "$2" != "it" ] ; then
phelp phelp
fi fi
python `dirname $0`/../domotika/clouds/google/tts.py $1 $2 "${3}" #python `dirname $0`/../domotika/clouds/google/tts.py $1 $2 "${3}"
python `dirname $0`/../domotika/clouds/responsivevoice/tts.py $1 $2 "${3}"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment