Index: chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background.js |
diff --git a/chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background.js b/chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background.js |
index f8bf898a6a625996064ae6425745a58c4af174c9..be031a9bf8d780ea4cbd1b544d4f2996d5add30d 100644 |
--- a/chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background.js |
+++ b/chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background.js |
@@ -57,7 +57,7 @@ cvox.TtsBackground = function(opt_enableMath) { |
// specified. |
if (this.ttsProperties['lang'] == undefined) { |
this.ttsProperties['lang'] = |
- chrome.i18n.getMessage('@@ui_locale').replace('_', '-'); |
+ chrome.i18n.getUILanguage(); |
} |
this.lastEventType = 'end'; |
@@ -680,24 +680,30 @@ cvox.TtsBackground.prototype.clearTimeout_ = function() { |
* Update the current voice used to speak based upon values in storage. If that |
* does not succeed, fallback to use system locale when picking a voice. |
* @param {string} voiceName Voice name to set. |
+ * @param {function(string) : void=} opt_callback Called when the voice is |
+ * determined. |
* @private |
*/ |
-cvox.TtsBackground.prototype.updateVoice_ = function(voiceName) { |
+cvox.TtsBackground.prototype.updateVoice_ = function(voiceName, opt_callback) { |
chrome.tts.getVoices(goog.bind(function(voices) { |
- var currentLocale = chrome.i18n.getMessage('@@ui_locale').replace('_', '-'); |
- |
- // TODO(dtseng): Prefer voices having the default property once we switch to |
- // web speech. See crbug.com/544139. |
- |
- var newVoice = voices.find( |
- function(v) { return v.voiceName == voiceName; }) || |
- voices.find(function(v) { return v.lang === currentLocale; }) || |
- voices.find(function(v) { return currentLocale.startsWith(v.lang); }) || |
- voices[0]; |
- |
- if (newVoice) { |
- this.currentVoice = newVoice.voiceName; |
- this.startSpeakingNextItemInQueue_(); |
- } |
+ chrome.i18n.getAcceptLanguages(goog.bind(function(acceptLanguages) { |
+ var currentLocale = acceptLanguages[0] || |
+ chrome.i18n.getUILanguage() || ''; |
+ var match = voices.find.bind(voices); |
+ var newVoice = |
+ match(function(v) { return v.voiceName == voiceName; }) || |
+ match(function(v) { return v.lang === currentLocale; }) || |
+ match(function(v) { return currentLocale.startsWith(v.lang); }) || |
+ match(function(v) { return v.lang && |
+ v.lang.startsWith(currentLocale); }) || |
+ voices[0]; |
+ |
+ if (newVoice) { |
+ this.currentVoice = newVoice.voiceName; |
+ this.startSpeakingNextItemInQueue_(); |
+ } |
+ if (opt_callback) |
+ opt_callback(this.currentVoice); |
+ }, this)); |
}, this)); |
}; |