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

Commit

Permalink
Select the TTS voice using locale matching based on RFC 4647. Fixes #…
Browse files Browse the repository at this point in the history
…2352 (#4197)

Signed-off-by: Henning Treu <henning.treu@telekom.de>
  • Loading branch information
htreu authored and kaikreuzer committed Sep 5, 2017
1 parent 0704122 commit 89a78cb
Showing 1 changed file with 6 additions and 7 deletions.
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

0 comments on commit 89a78cb

Please sign in to comment.