| Index: chrome/browser/resources/access_chromevox/audio/common/local_tts_manager.js
|
| ===================================================================
|
| --- chrome/browser/resources/access_chromevox/audio/common/local_tts_manager.js (revision 0)
|
| +++ chrome/browser/resources/access_chromevox/audio/common/local_tts_manager.js (revision 0)
|
| @@ -0,0 +1,151 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +/**
|
| + * @fileoverview This is the ChromeVox feedback core TTS implementation. It
|
| + * is responsible for speaking, playing earcons and state
|
| + * management.
|
| + */
|
| +
|
| +goog.provide('cvox.LocalTtsManager');
|
| +
|
| +goog.require('cvox.AbstractTts');
|
| +goog.require('cvox.AbstractTtsManager');
|
| +
|
| +/**
|
| + * This class is responsible for the ChromeVox feedback in terms of
|
| + * speech. It also stores the TTS configuration state.
|
| + *
|
| + * @constructor
|
| + * @extends {cvox.AbstractTtsManager}
|
| + *
|
| + * @param {Array} ttsEngines An array of TTS engine constructors.
|
| + * @param {Array} ttsProperties The default TTS properties to use.
|
| + */
|
| +cvox.LocalTtsManager = function(ttsEngines, ttsProperties) {
|
| + //Inherit AbstractTtsManager
|
| + cvox.AbstractTtsManager.call(this);
|
| +
|
| + this.ttsEngines = ttsEngines;
|
| + this.initializedTtsEngines = new Array(ttsEngines.length);
|
| + this.currentTtsEngineIndex = -1;
|
| + this.nextTtsEngine(false);
|
| + this.initializeTtsPropertiesToDefault(ttsProperties);
|
| +};
|
| +goog.inherits(cvox.LocalTtsManager, cvox.AbstractTtsManager);
|
| +
|
| +/**
|
| + * @return {string} The human-readable name of this instance.
|
| + */
|
| +cvox.LocalTtsManager.prototype.getName = function() {
|
| + return 'LocalTtsManager';
|
| +};
|
| +
|
| +/**
|
| + * Speaks the given string using the specified queueMode and properties.
|
| + * @param {string} textString The string of text to be spoken.
|
| + * @param {number} queueMode The queue mode: 0 for flush, 1 for adding to queue.
|
| + * @param {Object} properties Speech properties to use for this utterance.
|
| + */
|
| +cvox.LocalTtsManager.prototype.speak = function(textString, queueMode,
|
| + properties) {
|
| + cvox.LocalTtsManager.superClass_.speak.call(this, textString, queueMode,
|
| + properties);
|
| + if (!this.currentTtsEngine) {
|
| + return;
|
| + }
|
| + this.currentTtsEngine.speak(textString, queueMode, properties);
|
| +};
|
| +
|
| +/**
|
| + * Returns true if the TTS is currently speaking.
|
| + * @return {boolean} True if the TTS is speaking.
|
| + */
|
| +cvox.LocalTtsManager.prototype.isSpeaking = function() {
|
| + cvox.LocalTtsManager.superClass_.isSpeaking.call(this);
|
| + if (!this.currentTtsEngine) {
|
| + return false;
|
| + }
|
| + return this.currentTtsEngine.isSpeaking();
|
| +};
|
| +
|
| +/**
|
| + * Stops speech.
|
| + */
|
| +cvox.LocalTtsManager.prototype.stop = function() {
|
| + cvox.LocalTtsManager.superClass_.stop.call(this);
|
| + if (!this.currentTtsEngine) {
|
| + return;
|
| + }
|
| + this.currentTtsEngine.stop();
|
| +};
|
| +
|
| +/**
|
| + * Initializes the default properties of all the available TTS engines.
|
| + * @param {Array} ttsProperties An Array of TTS properties objects for all
|
| + * available TTS engines.
|
| + */
|
| +cvox.LocalTtsManager.prototype.initializeTtsPropertiesToDefault =
|
| + function(ttsProperties) {
|
| + if (!ttsProperties)
|
| + return;
|
| + for (var i = 0; i < this.ttsEngines.length; i++) {
|
| + if (this.ttsProperties[i])
|
| + this.ttsEngines[i].setDefaultTtsProperties(this.ttsProperties[i]);
|
| + }
|
| +};
|
| +
|
| +/**
|
| + * Switch to the next TTS engine and optionally announce its name.
|
| + * If not TTS engines have been specified this function is a NOOP.
|
| + * @param {boolean} announce If true, will announce the name of the
|
| + * new TTS engine.
|
| + */
|
| +cvox.LocalTtsManager.prototype.nextTtsEngine = function(announce) {
|
| + cvox.LocalTtsManager.superClass_.nextTtsEngine.call(this, announce);
|
| + if (!this.ttsEngines) {
|
| + return;
|
| + }
|
| + if (this.currentTtsEngine) {
|
| + this.currentTtsEngine.stop();
|
| + }
|
| + this.currentTtsEngineIndex =
|
| + (this.currentTtsEngineIndex + 1) % this.ttsEngines.length;
|
| + this.currentTtsEngine = null;
|
| + try {
|
| + this.currentTtsEngine =
|
| + this.initializedTtsEngines[this.currentTtsEngineIndex] ||
|
| + new this.ttsEngines[this.currentTtsEngineIndex];
|
| + this.initializedTtsEngines[this.currentTtsEngineIndex] =
|
| + this.currentTtsEngine;
|
| + this.log('Switching to speech engine: ' + this.currentTtsEngine.getName());
|
| + if (announce) {
|
| + this.speak(this.currentTtsEngine.getName(),
|
| + cvox.AbstractTts.QUEUE_MODE_FLUSH,
|
| + this.ttsProperties[this.currentTtsEngineIndex]);
|
| + }
|
| + } catch (err) {
|
| + this.log('error switching to engine #' +
|
| + this.currentTtsEngineIndex + ' ' + err);
|
| + }
|
| +};
|
| +
|
| +/**
|
| + * Increases a TTS speech property.
|
| + * @param {string} property_name The name of the property to increase.
|
| + */
|
| +cvox.LocalTtsManager.prototype.increaseProperty = function(property_name) {
|
| + cvox.LocalTtsManager.superClass_.increaseProperty.call(this, property_name);
|
| + this.currentTtsEngine.increaseProperty(property_name);
|
| +};
|
| +
|
| +/**
|
| + * Decreases a TTS speech property.
|
| + * @param {string} property_name The name of the property to decrease.
|
| + */
|
| +cvox.LocalTtsManager.prototype.decreaseProperty = function(property_name) {
|
| + cvox.LocalTtsManager.superClass_.decreaseProperty.call(this, property_name);
|
| + this.currentTtsEngine.decreaseProperty(property_name);
|
| +};
|
| +
|
|
|
| Property changes on: chrome/browser/resources/access_chromevox/audio/common/local_tts_manager.js
|
| ___________________________________________________________________
|
| Added: svn:executable
|
| + *
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|