OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview Text-To-Speech engine powered by GooSS. This engine relies on |
| 7 * HTML5. |
| 8 * |
| 9 * Note: There are currently still a few problems with long utterances and the |
| 10 * way GooSS generates MP3s. |
| 11 */ |
| 12 |
| 13 goog.provide('cvox.ChromeVoxGoossEngine'); |
| 14 |
| 15 goog.require('cvox.AbstractTts'); |
| 16 |
| 17 /** |
| 18 * @constructor |
| 19 * @extends {cvox.AbstractTts} |
| 20 */ |
| 21 cvox.ChromeVoxGoossEngine = function() { |
| 22 //Inherit AbstractTts |
| 23 cvox.AbstractTts.call(this); |
| 24 |
| 25 this.speechServerUrl = 'http://www.google.com/speech-api/' + |
| 26 'v1/synthesize?lang=en-us&text='; |
| 27 this.audioElem = document.createElement('audio'); |
| 28 }; |
| 29 goog.inherits(cvox.ChromeVoxGoossEngine, cvox.AbstractTts); |
| 30 |
| 31 /** |
| 32 * @return {string} The human-readable name of the speech engine. |
| 33 */ |
| 34 cvox.ChromeVoxGoossEngine.prototype.getName = function() { |
| 35 return 'Google Network Speech'; |
| 36 }; |
| 37 |
| 38 /** |
| 39 * Speaks the given string using the specified queueMode and properties. |
| 40 * @param {string} textString The string of text to be spoken. |
| 41 * @param {number=} queueMode The queue mode: AbstractTts.QUEUE_MODE_FLUSH |
| 42 * for flush, AbstractTts.QUEUE_MODE_QUEUE for adding to queue. |
| 43 * @param {Object=} properties Speech properties to use for this utterance. |
| 44 */ |
| 45 cvox.ChromeVoxGoossEngine.prototype.speak = function(textString, queueMode, |
| 46 properties) { |
| 47 cvox.ChromeVoxGoossEngine.superClass_.speak.call(this, textString, |
| 48 queueMode, properties); |
| 49 // TODO: Implement speech queue so that queued speech is possible |
| 50 this.audioElem.pause(); |
| 51 this.audioElem.src = this.speechServerUrl + escape(textString); |
| 52 this.audioElem.autoplay = true; |
| 53 this.isSpeaking_ = true; |
| 54 this.audioElem.addEventListener('ended', function(evt) { |
| 55 this.isSpeaking_ = false; |
| 56 }, true); |
| 57 }; |
| 58 |
| 59 /** |
| 60 * Returns true if the TTS is currently speaking. |
| 61 * @return {boolean} True if the TTS is speaking. |
| 62 */ |
| 63 cvox.ChromeVoxGoossEngine.prototype.isSpeaking = function() { |
| 64 cvox.ChromeVoxGoossEngine.superClass_.isSpeaking.call(this); |
| 65 return this.isSpeaking_; |
| 66 }; |
| 67 |
| 68 /** |
| 69 * Stops speech. |
| 70 */ |
| 71 cvox.ChromeVoxGoossEngine.prototype.stop = function() { |
| 72 cvox.ChromeVoxGoossEngine.superClass_.stop.call(this); |
| 73 this.audioElem.pause(); |
| 74 }; |
OLD | NEW |