Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: chrome/browser/resources/access_chromevox/audio/common/local_tts_manager.js

Issue 6254007: Adding ChromeVox as a component extensions (enabled only for ChromeOS, for no... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:executable
+ *
Added: svn:eol-style
+ LF
OLDNEW
(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 This is the ChromeVox feedback core TTS implementation. It
7 * is responsible for speaking, playing earcons and state
8 * management.
9 */
10
11 goog.provide('cvox.LocalTtsManager');
12
13 goog.require('cvox.AbstractTts');
14 goog.require('cvox.AbstractTtsManager');
15
16 /**
17 * This class is responsible for the ChromeVox feedback in terms of
18 * speech. It also stores the TTS configuration state.
19 *
20 * @constructor
21 * @extends {cvox.AbstractTtsManager}
22 *
23 * @param {Array} ttsEngines An array of TTS engine constructors.
24 * @param {Array} ttsProperties The default TTS properties to use.
25 */
26 cvox.LocalTtsManager = function(ttsEngines, ttsProperties) {
27 //Inherit AbstractTtsManager
28 cvox.AbstractTtsManager.call(this);
29
30 this.ttsEngines = ttsEngines;
31 this.initializedTtsEngines = new Array(ttsEngines.length);
32 this.currentTtsEngineIndex = -1;
33 this.nextTtsEngine(false);
34 this.initializeTtsPropertiesToDefault(ttsProperties);
35 };
36 goog.inherits(cvox.LocalTtsManager, cvox.AbstractTtsManager);
37
38 /**
39 * @return {string} The human-readable name of this instance.
40 */
41 cvox.LocalTtsManager.prototype.getName = function() {
42 return 'LocalTtsManager';
43 };
44
45 /**
46 * Speaks the given string using the specified queueMode and properties.
47 * @param {string} textString The string of text to be spoken.
48 * @param {number} queueMode The queue mode: 0 for flush, 1 for adding to queue.
49 * @param {Object} properties Speech properties to use for this utterance.
50 */
51 cvox.LocalTtsManager.prototype.speak = function(textString, queueMode,
52 properties) {
53 cvox.LocalTtsManager.superClass_.speak.call(this, textString, queueMode,
54 properties);
55 if (!this.currentTtsEngine) {
56 return;
57 }
58 this.currentTtsEngine.speak(textString, queueMode, properties);
59 };
60
61 /**
62 * Returns true if the TTS is currently speaking.
63 * @return {boolean} True if the TTS is speaking.
64 */
65 cvox.LocalTtsManager.prototype.isSpeaking = function() {
66 cvox.LocalTtsManager.superClass_.isSpeaking.call(this);
67 if (!this.currentTtsEngine) {
68 return false;
69 }
70 return this.currentTtsEngine.isSpeaking();
71 };
72
73 /**
74 * Stops speech.
75 */
76 cvox.LocalTtsManager.prototype.stop = function() {
77 cvox.LocalTtsManager.superClass_.stop.call(this);
78 if (!this.currentTtsEngine) {
79 return;
80 }
81 this.currentTtsEngine.stop();
82 };
83
84 /**
85 * Initializes the default properties of all the available TTS engines.
86 * @param {Array} ttsProperties An Array of TTS properties objects for all
87 * available TTS engines.
88 */
89 cvox.LocalTtsManager.prototype.initializeTtsPropertiesToDefault =
90 function(ttsProperties) {
91 if (!ttsProperties)
92 return;
93 for (var i = 0; i < this.ttsEngines.length; i++) {
94 if (this.ttsProperties[i])
95 this.ttsEngines[i].setDefaultTtsProperties(this.ttsProperties[i]);
96 }
97 };
98
99 /**
100 * Switch to the next TTS engine and optionally announce its name.
101 * If not TTS engines have been specified this function is a NOOP.
102 * @param {boolean} announce If true, will announce the name of the
103 * new TTS engine.
104 */
105 cvox.LocalTtsManager.prototype.nextTtsEngine = function(announce) {
106 cvox.LocalTtsManager.superClass_.nextTtsEngine.call(this, announce);
107 if (!this.ttsEngines) {
108 return;
109 }
110 if (this.currentTtsEngine) {
111 this.currentTtsEngine.stop();
112 }
113 this.currentTtsEngineIndex =
114 (this.currentTtsEngineIndex + 1) % this.ttsEngines.length;
115 this.currentTtsEngine = null;
116 try {
117 this.currentTtsEngine =
118 this.initializedTtsEngines[this.currentTtsEngineIndex] ||
119 new this.ttsEngines[this.currentTtsEngineIndex];
120 this.initializedTtsEngines[this.currentTtsEngineIndex] =
121 this.currentTtsEngine;
122 this.log('Switching to speech engine: ' + this.currentTtsEngine.getName());
123 if (announce) {
124 this.speak(this.currentTtsEngine.getName(),
125 cvox.AbstractTts.QUEUE_MODE_FLUSH,
126 this.ttsProperties[this.currentTtsEngineIndex]);
127 }
128 } catch (err) {
129 this.log('error switching to engine #' +
130 this.currentTtsEngineIndex + ' ' + err);
131 }
132 };
133
134 /**
135 * Increases a TTS speech property.
136 * @param {string} property_name The name of the property to increase.
137 */
138 cvox.LocalTtsManager.prototype.increaseProperty = function(property_name) {
139 cvox.LocalTtsManager.superClass_.increaseProperty.call(this, property_name);
140 this.currentTtsEngine.increaseProperty(property_name);
141 };
142
143 /**
144 * Decreases a TTS speech property.
145 * @param {string} property_name The name of the property to decrease.
146 */
147 cvox.LocalTtsManager.prototype.decreaseProperty = function(property_name) {
148 cvox.LocalTtsManager.superClass_.decreaseProperty.call(this, property_name);
149 this.currentTtsEngine.decreaseProperty(property_name);
150 };
151
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698