console_tts.js revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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 TTS engine that writes to window.console.
7 */
8
9goog.provide('cvox.ConsoleTts');
10
11goog.require('cvox.AbstractTts');
12goog.require('cvox.TtsInterface');
13
14/**
15 * @constructor
16 * @implements {cvox.TtsInterface}
17 */
18cvox.ConsoleTts = function() {
19  /**
20   * True if the console TTS is enabled by the user.
21   * @type {boolean}
22   * @private
23   */
24  this.enabled_ = false;
25};
26goog.addSingletonGetter(cvox.ConsoleTts);
27
28
29/** @override */
30cvox.ConsoleTts.prototype.speak = function(textString, queueMode, properties) {
31  if (this.enabled_ && window['console']) {
32    var logStr = 'Speak';
33    if (queueMode == cvox.AbstractTts.QUEUE_MODE_FLUSH) {
34      logStr += ' (I)';
35    } else if (queueMode == cvox.AbstractTts.QUEUE_MODE_CATEGORY_FLUSH) {
36      logStr += ' (C)';
37    } else {
38      logStr += ' (Q)';
39    }
40    if (properties && properties.category) {
41      logStr += ' category=' + properties.category;
42    }
43    logStr += ' "' + textString + '"';
44    window['console']['log'](logStr);
45
46    if (properties && properties['startCallback'] != undefined) {
47      window.console.log('  using startCallback');
48    }
49
50    if (properties && properties['endCallback'] != undefined) {
51      window.console.log('  using endCallback');
52    }
53  }
54  return this;
55};
56
57/** @override */
58cvox.ConsoleTts.prototype.isSpeaking = function() { return false; };
59
60/** @override */
61cvox.ConsoleTts.prototype.stop = function() {
62  if (this.enabled_) {
63    window['console']['log']('Stop');
64  }
65};
66
67/** @override */
68cvox.ConsoleTts.prototype.addCapturingEventListener = function(listener) { };
69
70/** @override */
71cvox.ConsoleTts.prototype.increaseOrDecreaseProperty = function() { };
72
73/**
74 * Sets the enabled bit.
75 * @param {boolean} enabled The new enabled bit.
76 */
77cvox.ConsoleTts.prototype.setEnabled = function(enabled) {
78  this.enabled_ = enabled;
79};
80
81/** @override */
82cvox.ConsoleTts.prototype.getDefaultProperty = function(property) { };
83