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

Side by Side Diff: chrome/browser/resources/access_chromevox/audio/common/abstract_tts.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 Base class for Text-To-Speech-Engines.
7 */
8
9 goog.provide('cvox.AbstractTts');
10
11 goog.require('cvox.AbstractLogger');
12
13 /**
14 * Creates a new instance.
15 * @constructor
16 * @extends {cvox.AbstractLogger}
17 */
18 cvox.AbstractTts = function() {
19 //Inherit AbstractLogger
20 cvox.AbstractLogger.call(this);
21 this.ttsProperties = new Object();
22 };
23 goog.inherits(cvox.AbstractTts, cvox.AbstractLogger);
24
25 /**
26 * Default TTS properties for this TTS engine.
27 * @type {Object}
28 * @protected
29 */
30 cvox.AbstractTts.prototype.ttsProperties;
31
32 /**
33 * Override the super class method to configure logging.
34 * @return {boolean} If logging is enabled.
35 */
36 cvox.AbstractTts.prototype.logEnabled = function() {
37 return cvox.AbstractTts.DEBUG;
38 };
39
40 /**
41 * Speaks the given string using the specified queueMode and properties.
42 * @param {string} textString The string of text to be spoken.
43 * @param {number=} queueMode The queue mode: cvox.AbstractTts.QUEUE_MODE_FLUSH
44 * for flush, cvox.AbstractTts.QUEUE_MODE_QUEUE for adding to queue.
45 * @param {Object=} properties Speech properties to use for this utterance.
46 */
47 cvox.AbstractTts.prototype.speak = function(textString, queueMode,
48 properties) {
49 if (this.logEnabled()) {
50 this.log('[' + this.getName() + '] speak(' + textString + ', ' + queueMode +
51 (properties ? ', ' + properties.toString() : '') + ')');
52 }
53 };
54
55 /**
56 * Returns true if the TTS is currently speaking.
57 * @return {boolean} True if the TTS is speaking.
58 */
59 cvox.AbstractTts.prototype.isSpeaking = function() {
60 if (this.logEnabled()) {
61 this.log('[' + this.getName() + '] isSpeaking()');
62 }
63 return false;
64 };
65
66 /**
67 * Stops speech.
68 */
69 cvox.AbstractTts.prototype.stop = function() {
70 if (this.logEnabled()) {
71 this.log('[' + this.getName() + '] stop()');
72 }
73 };
74
75 /**
76 * Retrieves the default TTS properties for this TTS engine.
77 * @return {Object} Default TTS properties.
78 */
79 cvox.AbstractTts.prototype.getDefaultTtsProperties = function() {
80 return this.ttsProperties;
81 };
82
83 /**
84 * Sets the default TTS properties for this TTS engine.
85 * @param {Object} ttsProperties Default TTS properties.
86 */
87 cvox.AbstractTts.prototype.setDefaultTtsProperties = function(ttsProperties) {
88 this.ttsProperties = ttsProperties;
89 };
90
91 /**
92 * Increases a TTS speech property.
93 * @param {string} property_name The name of the property to increase.
94 */
95 cvox.AbstractTts.prototype.increaseProperty = function(property_name) {
96 if (property_name == cvox.AbstractTts.TTS_PROPERTY_RATE) {
97 this.ttsProperties.rate = this.increasePropertyValue(
98 this.ttsProperties.rate);
99 this.speak(cvox.AbstractTts.str.increaseRate, 0, this.ttsProperties);
100 } else if (property_name == cvox.AbstractTts.TTS_PROPERTY_PITCH) {
101 this.ttsProperties.pitch = this.increasePropertyValue(
102 this.ttsProperties.pitch);
103 this.speak(cvox.AbstractTts.str.increasePitch, 0, this.ttsProperties);
104 } else if (property_name == cvox.AbstractTts.TTS_PROPERTY_VOLUME) {
105 this.ttsProperties.volume = this.increasePropertyValue(
106 this.ttsProperties.volume);
107 this.speak(cvox.AbstractTts.str.increaseVolume, 0, this.ttsProperties);
108 }
109 };
110
111 /**
112 * Decreases a TTS speech property.
113 * @param {string} property_name The name of the property to decrease.
114 */
115 cvox.AbstractTts.prototype.decreaseProperty = function(property_name) {
116 if (property_name == cvox.AbstractTts.TTS_PROPERTY_RATE) {
117 this.ttsProperties.rate = this.decreasePropertyValue(
118 this.ttsProperties.rate);
119 this.speak(cvox.AbstractTts.str.decreaseRate, 0, this.ttsProperties);
120 } else if (property_name == cvox.AbstractTts.TTS_PROPERTY_PITCH) {
121 this.ttsProperties.pitch = this.decreasePropertyValue(
122 this.ttsProperties.pitch);
123 this.speak(cvox.AbstractTts.str.decreasePitch, 0, this.ttsProperties);
124 } else if (property_name == cvox.AbstractTts.TTS_PROPERTY_VOLUME) {
125 this.ttsProperties.volume = this.decreasePropertyValue(
126 this.ttsProperties.volume);
127 this.speak(cvox.AbstractTts.str.decreaseVolume, 0, this.ttsProperties);
128 }
129 };
130
131 /**
132 * Merges the given properties with the default ones.
133 * @param {Object=} properties The properties to merge with the default.
134 * @return {Object} The merged properties.
135 */
136 cvox.AbstractTts.prototype.mergeProperties = function(properties) {
137 if (!properties) {
138 return this.ttsProperties;
139 }
140 // Merge the default properties with the properties from this message,
141 // so that the defaults are always passed along but the message
142 // always overrides.
143 var mergedProperties = new Object();
144 for (var p in this.ttsProperties) {
145 mergedProperties[p] = this.ttsProperties[p];
146 }
147 for (var p in properties) {
148 mergedProperties[p] = properties[p];
149 }
150 return mergedProperties;
151 };
152
153 /**
154 * Decrease by 0.1 the value of a TTS property that's normally in the range
155 * 0.0 - 1.0, and make sure it doesn't end up smaller than 0.0. Return the
156 * new value.
157 * @param {number} current_value The current value of the property.
158 * @return {number} The new value.
159 */
160 cvox.AbstractTts.prototype.decreasePropertyValue = function(current_value) {
161 return Math.max(0.0, current_value - 0.1);
162 };
163
164 /**
165 * Increase by 0.1 the value of a TTS property that's normally in the range
166 * 0.0 - 1.0, and make sure it doesn't end up larger than 1.0. Return the
167 * new value.
168 * @param {number} current_value The current value of the property.
169 * @return {number} The new value.
170 */
171 cvox.AbstractTts.prototype.increasePropertyValue = function(current_value) {
172 return Math.min(1.0, current_value + 0.1);
173 };
174
175 /**
176 * TTS rate property.
177 * @type {string}
178 */
179 cvox.AbstractTts.TTS_PROPERTY_RATE = 'Rate';
180
181 /**
182 * TTS pitch property.
183 * @type {string}
184 */
185 cvox.AbstractTts.TTS_PROPERTY_PITCH = 'Pitch';
186
187 /**
188 * TTS volume property.
189 * @type {string}
190 */
191 cvox.AbstractTts.TTS_PROPERTY_VOLUME = 'Volume';
192
193 /**
194 * Flag indicating if the TTS is being debugged.
195 * @type {boolean}
196 */
197 cvox.AbstractTts.DEBUG = true;
198
199 /**
200 * Speech queue mode that interrupts the current utterance.
201 * @type {number}
202 */
203 cvox.AbstractTts.QUEUE_MODE_FLUSH = 0;
204
205 /**
206 * Speech queue mode that does not interrupt the current utterance.
207 * @type {number}
208 */
209 cvox.AbstractTts.QUEUE_MODE_QUEUE = 1;
210
211 /**
212 * String constants.
213 * @type {Object}
214 */
215 cvox.AbstractTts.str = {
216 'increaseRate': 'increasing rate',
217 'increasePitch': 'increasing pitch',
218 'increaseVolume': 'increasing volume',
219 'decreaseRate': 'decreasing rate',
220 'decreasePitch': 'decreasing pitch',
221 'decreaseVolume': 'decreasing volume'
222 };
223
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698