Home | History | Annotate | Download | only in common
      1 // Copyright 2014 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 A composite TTS sends allows ChromeVox to use
      7  * multiple TTS engines at the same time.
      8  *
      9  */
     10 
     11 goog.provide('cvox.CompositeTts');
     12 
     13 goog.require('cvox.TtsInterface');
     14 
     15 /**
     16  * A Composite Tts
     17  * @constructor
     18  * @implements {cvox.TtsInterface}
     19  */
     20 cvox.CompositeTts = function() {
     21   /**
     22    * @type {Array.<cvox.TtsInterface>}
     23    * @private
     24    */
     25   this.ttsEngines_ = [];
     26 };
     27 
     28 
     29 /**
     30  * Adds a TTS engine to the composite TTS
     31  * @param {cvox.TtsInterface} tts The TTS to add.
     32  * @return {cvox.CompositeTts} this.
     33  */
     34 cvox.CompositeTts.prototype.add = function(tts) {
     35   this.ttsEngines_.push(tts);
     36   return this;
     37 };
     38 
     39 
     40 /**
     41  * @override
     42  */
     43 cvox.CompositeTts.prototype.speak =
     44     function(textString, queueMode, properties) {
     45   this.ttsEngines_.forEach(function(engine) {
     46     engine.speak(textString, queueMode, properties);
     47   });
     48 };
     49 
     50 
     51 /**
     52  * Returns true if any of the TTSes are still speaking.
     53  * @override
     54  */
     55 cvox.CompositeTts.prototype.isSpeaking = function() {
     56   return this.ttsEngines_.some(function(engine) {
     57     return engine.isSpeaking();
     58   });
     59 };
     60 
     61 
     62 /**
     63  * @override
     64  */
     65 cvox.CompositeTts.prototype.stop = function() {
     66   this.ttsEngines_.forEach(function(engine) {
     67     engine.stop();
     68   });
     69 };
     70 
     71 
     72 /**
     73  * @override
     74  */
     75 cvox.CompositeTts.prototype.addCapturingEventListener = function(listener) {
     76   this.ttsEngines_.forEach(function(engine) {
     77     engine.addCapturingEventListener(listener);
     78   });
     79 };
     80 
     81 
     82 /**
     83  * @override
     84  */
     85 cvox.CompositeTts.prototype.increaseOrDecreaseProperty =
     86     function(propertyName, increase) {
     87   this.ttsEngines_.forEach(function(engine) {
     88     engine.increaseOrDecreaseProperty(propertyName, increase);
     89   });
     90 };
     91 
     92 
     93 /**
     94  * @override
     95  */
     96 cvox.CompositeTts.prototype.getDefaultProperty = function(property) {
     97   for (var i = 0, engine; engine = this.ttsEngines_[i]; i++) {
     98     var value = engine.getDefaultProperty(property);
     99     if (value) {
    100       return value;
    101     }
    102   }
    103 };
    104