Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Select the TTS voice using locale matching based on RFC 4647. #4197

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -97,7 +97,8 @@ protected void modified(Map<String, Object> config) {
if (config != null) {
this.keyword = config.containsKey(CONFIG_KEYWORD) ? config.get(CONFIG_KEYWORD).toString() : DEFAULT_KEYWORD;
this.listeningItem = config.containsKey(CONFIG_LISTENING_ITEM)
? config.get(CONFIG_LISTENING_ITEM).toString() : null;
? config.get(CONFIG_LISTENING_ITEM).toString()
: null;
this.defaultTTS = config.containsKey(CONFIG_DEFAULT_TTS) ? config.get(CONFIG_DEFAULT_TTS).toString() : null;
this.defaultSTT = config.containsKey(CONFIG_DEFAULT_STT) ? config.get(CONFIG_DEFAULT_STT).toString() : null;
this.defaultKS = config.containsKey(CONFIG_DEFAULT_KS) ? config.get(CONFIG_DEFAULT_KS).toString() : null;
Expand Down Expand Up @@ -339,15 +340,13 @@ public Voice getPreferredVoice(Set<Voice> voices) {
locales.add(currentVoice.getLocale());
}

// TODO: This can be activated for Java 8
// Determine preferred locale based on RFC 4647
// String ranges = locale.toLanguageTag();
// List<Locale.LanguageRange> languageRanges = Locale.LanguageRange.parse(ranges);
// Locale preferedLocale = Locale.lookup(languageRanges,locales);
Locale preferredLocale = locale;
String ranges = locale.toLanguageTag();
List<Locale.LanguageRange> languageRanges = Locale.LanguageRange.parse(ranges + "-*");
Locale preferredLocale = Locale.lookup(languageRanges, locales);

// As a last resort choose some Locale
if (null == preferredLocale) {
if (preferredLocale == null) {
preferredLocale = locales.iterator().next();
}

Expand Down