| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview Sends Text-To-Speech commands to Chrome's native TTS | 6 * @fileoverview Sends Text-To-Speech commands to Chrome's native TTS |
| 7 * extension API. | 7 * extension API. |
| 8 * | 8 * |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 this.propertyDefault['rate']); | 50 this.propertyDefault['rate']); |
| 51 this.ttsProperties['pitch'] = (parseFloat(localStorage['pitch']) || | 51 this.ttsProperties['pitch'] = (parseFloat(localStorage['pitch']) || |
| 52 this.propertyDefault['pitch']); | 52 this.propertyDefault['pitch']); |
| 53 this.ttsProperties['volume'] = (parseFloat(localStorage['volume']) || | 53 this.ttsProperties['volume'] = (parseFloat(localStorage['volume']) || |
| 54 this.propertyDefault['volume']); | 54 this.propertyDefault['volume']); |
| 55 | 55 |
| 56 // Use the current locale as the speech language if not otherwise | 56 // Use the current locale as the speech language if not otherwise |
| 57 // specified. | 57 // specified. |
| 58 if (this.ttsProperties['lang'] == undefined) { | 58 if (this.ttsProperties['lang'] == undefined) { |
| 59 this.ttsProperties['lang'] = | 59 this.ttsProperties['lang'] = |
| 60 chrome.i18n.getMessage('@@ui_locale').replace('_', '-'); | 60 chrome.i18n.getUILanguage(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 this.lastEventType = 'end'; | 63 this.lastEventType = 'end'; |
| 64 | 64 |
| 65 /** @private {number} */ | 65 /** @private {number} */ |
| 66 this.currentPunctuationEcho_ = | 66 this.currentPunctuationEcho_ = |
| 67 parseInt(localStorage[cvox.AbstractTts.PUNCTUATION_ECHO] || 1, 10); | 67 parseInt(localStorage[cvox.AbstractTts.PUNCTUATION_ECHO] || 1, 10); |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * @type {!Array<{name:(string), | 70 * @type {!Array<{name:(string), |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 clearTimeout(this.timeoutId_); | 673 clearTimeout(this.timeoutId_); |
| 674 this.timeoutId_ = undefined; | 674 this.timeoutId_ = undefined; |
| 675 } | 675 } |
| 676 }; | 676 }; |
| 677 | 677 |
| 678 | 678 |
| 679 /** | 679 /** |
| 680 * Update the current voice used to speak based upon values in storage. If that | 680 * Update the current voice used to speak based upon values in storage. If that |
| 681 * does not succeed, fallback to use system locale when picking a voice. | 681 * does not succeed, fallback to use system locale when picking a voice. |
| 682 * @param {string} voiceName Voice name to set. | 682 * @param {string} voiceName Voice name to set. |
| 683 * @param {function(string) : void=} opt_callback Called when the voice is |
| 684 * determined. |
| 683 * @private | 685 * @private |
| 684 */ | 686 */ |
| 685 cvox.TtsBackground.prototype.updateVoice_ = function(voiceName) { | 687 cvox.TtsBackground.prototype.updateVoice_ = function(voiceName, opt_callback) { |
| 686 chrome.tts.getVoices(goog.bind(function(voices) { | 688 chrome.tts.getVoices(goog.bind(function(voices) { |
| 687 var currentLocale = chrome.i18n.getMessage('@@ui_locale').replace('_', '-'); | 689 chrome.i18n.getAcceptLanguages(goog.bind(function(acceptLanguages) { |
| 690 var currentLocale = acceptLanguages[0] || |
| 691 chrome.i18n.getUILanguage() || ''; |
| 692 var match = voices.find.bind(voices); |
| 693 var newVoice = |
| 694 match(function(v) { return v.voiceName == voiceName; }) || |
| 695 match(function(v) { return v.lang === currentLocale; }) || |
| 696 match(function(v) { return currentLocale.startsWith(v.lang); }) || |
| 697 match(function(v) { return v.lang && |
| 698 v.lang.startsWith(currentLocale); }) || |
| 699 voices[0]; |
| 688 | 700 |
| 689 // TODO(dtseng): Prefer voices having the default property once we switch to | 701 if (newVoice) { |
| 690 // web speech. See crbug.com/544139. | 702 this.currentVoice = newVoice.voiceName; |
| 691 | 703 this.startSpeakingNextItemInQueue_(); |
| 692 var newVoice = voices.find( | 704 } |
| 693 function(v) { return v.voiceName == voiceName; }) || | 705 if (opt_callback) |
| 694 voices.find(function(v) { return v.lang === currentLocale; }) || | 706 opt_callback(this.currentVoice); |
| 695 voices.find(function(v) { return currentLocale.startsWith(v.lang); }) || | 707 }, this)); |
| 696 voices[0]; | |
| 697 | |
| 698 if (newVoice) { | |
| 699 this.currentVoice = newVoice.voiceName; | |
| 700 this.startSpeakingNextItemInQueue_(); | |
| 701 } | |
| 702 }, this)); | 708 }, this)); |
| 703 }; | 709 }; |
| OLD | NEW |