From ab220f45df3029fd7caed3e86a3abfbf1aecd1f0 Mon Sep 17 00:00:00 2001 From: Kelly Davis Date: Fri, 24 Apr 2015 16:01:08 -0700 Subject: [PATCH] Switched from the off-device GET/server based TTS to the on-device WebSpeech API based TTS --- main.js | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/main.js b/main.js index bd3a15e..1ef3a4d 100755 --- a/main.js +++ b/main.js @@ -182,26 +182,16 @@ var VoiceCommandsInterface = { this.setSpeakButtonState(true); this.updateStatusText(aSentence); - // XXXAus: Language should be detected based on system language. - var language = 'en'; - // XXXAus: Speech synthesis should be a local service. - var baseURL = 'http://speechan.cloudapp.net/weblayer/synth.ashx?lng=' + - language + - '&msg='; - - // XXXAus: Using a url to an external service is only a temporary solution. - var url = baseURL + aSentence; - if (aIsWaitingForCommandResponse) { this._interpretingCommand = true; } // Wait an extra 100ms for the audio output to stabilize off. setTimeout(function() { - var e = document.createElement('audio'); - e.src = url; - e.setAttribute('autoplay', 'true'); - e.addEventListener('ended', (function() { + var speechSynthesisUtterance = new SpeechSynthesisUtterance(aSentence); + // XXX: Language should be detected based on system language. + speechSynthesisUtterance.lang = 'en'; + speechSynthesisUtterance.addEventListener('end', (function() { // Enable the speak button. this.setSpeakButtonState(false); // If we're waiting for a command, start listening. @@ -209,6 +199,7 @@ var VoiceCommandsInterface = { this.listen(); } }).bind(this)); + speechSynthesis.speak(speechSynthesisUtterance); }.bind(this), 100); },