From 9481a959cbee3d2703794d434686538c6f8d393b Mon Sep 17 00:00:00 2001 From: Hardy Date: Sat, 7 Nov 2020 17:38:19 +0100 Subject: [PATCH] Improve TTS initiatlization --- .../net/osmand/plus/voice/TTSCommandPlayerImpl.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java b/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java index 7a38c4198a..cdbb058cec 100644 --- a/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java +++ b/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java @@ -191,11 +191,18 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer { final float speechRate = cSpeechRate; final String[] lsplit = (language + "____.").split("[\\_\\-]"); - // constructor supports lang_country_variant - Locale newLocale0 = new Locale(lsplit[0], lsplit[1], lsplit[2]); - // #3344: Try Locale builder instead of constructor (only available from API 21). Also supports script (for now supported as trailing x_x_x_Scrp) + // constructor supports 'lang-country-variant' + Locale newLocale0 = new Locale(lsplit[0]); + try { + newLocale0 = new Locale(lsplit[0], lsplit[1]); + newLocale0 = new Locale(lsplit[0], lsplit[1], lsplit[2]); + } catch (RuntimeException e) { + // Falls back to language only + } + // #3344: Try Locale builder instead of constructor (only available from API 21). Also supports script (for now supported as trailing 'l-c-v-Scrp') if (android.os.Build.VERSION.SDK_INT >= 21) { try { + newLocale0 = new Locale.Builder().setLanguage(lsplit[0]).setScript(lsplit[3]).setRegion(lsplit[1]).build(); newLocale0 = new Locale.Builder().setLanguage(lsplit[0]).setScript(lsplit[3]).setRegion(lsplit[1]).setVariant(lsplit[2]).build(); } catch (RuntimeException e) { // Falls back to constructor