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(); |
dmazzoni
2016/11/17 22:49:38
Did you confirm that this is in the right
format,
David Tseng
2016/11/17 23:03:02
Yes, getMessage seems to be the outlier (xx_XX)
g
| |
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 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 * @private | 683 * @private |
684 */ | 684 */ |
685 cvox.TtsBackground.prototype.updateVoice_ = function(voiceName) { | 685 cvox.TtsBackground.prototype.updateVoice_ = function(voiceName) { |
686 chrome.tts.getVoices(goog.bind(function(voices) { | 686 chrome.tts.getVoices(goog.bind(function(voices) { |
687 var currentLocale = chrome.i18n.getMessage('@@ui_locale').replace('_', '-'); | 687 chrome.i18n.getAcceptLanguages(goog.bind(function(acceptLanguages) { |
688 var currentLocale = acceptLanguages[0] || | |
dmazzoni
2016/11/17 22:49:38
Ideally we should use all acceptLanguages?
Maybe a
David Tseng
2016/11/17 23:03:02
It's all kind of guess work at this point because
| |
689 chrome.i18n.getUILanguage() || ''; | |
690 var match = voices.find.bind(voices); | |
691 var newVoice = | |
692 match(function(v) { return v.voiceName == voiceName; }) || | |
693 match(function(v) { return v.lang === currentLocale; }) || | |
694 match(function(v) { return currentLocale.startsWith(v.lang); }) || | |
695 match(function(v) { return v.lang.startsWith(currentLocale); }) || | |
696 voices[0]; | |
688 | 697 |
689 // TODO(dtseng): Prefer voices having the default property once we switch to | 698 if (newVoice) { |
690 // web speech. See crbug.com/544139. | 699 this.currentVoice = newVoice.voiceName; |
691 | 700 this.startSpeakingNextItemInQueue_(); |
692 var newVoice = voices.find( | 701 } |
693 function(v) { return v.voiceName == voiceName; }) || | 702 }, this)); |
694 voices.find(function(v) { return v.lang === currentLocale; }) || | |
695 voices.find(function(v) { return currentLocale.startsWith(v.lang); }) || | |
696 voices[0]; | |
697 | |
698 if (newVoice) { | |
699 this.currentVoice = newVoice.voiceName; | |
700 this.startSpeakingNextItemInQueue_(); | |
701 } | |
702 }, this)); | 703 }, this)); |
703 }; | 704 }; |
OLD | NEW |