From 328f4cfdc9c377565b3fec2e7a6db764b331837e Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Tue, 28 Oct 2014 15:33:11 +0000 Subject: [PATCH] Test and fix Java to IANA country code mapping. --- .../reecedunn/espeak/test/SpeechSynthesisTest.java | 8 ++++++++ android/src/com/reecedunn/espeak/SpeechSynthesis.java | 11 ++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/android/eSpeakTests/src/com/reecedunn/espeak/test/SpeechSynthesisTest.java b/android/eSpeakTests/src/com/reecedunn/espeak/test/SpeechSynthesisTest.java index 6183fb7c..ee948db2 100644 --- a/android/eSpeakTests/src/com/reecedunn/espeak/test/SpeechSynthesisTest.java +++ b/android/eSpeakTests/src/com/reecedunn/espeak/test/SpeechSynthesisTest.java @@ -179,6 +179,14 @@ public class SpeechSynthesisTest extends TextToSpeechTestCase } } + public void testJavaToIanaCountryCode() + { + for (VoiceData.Voice data : VoiceData.voices) + { + assertThat(SpeechSynthesis.getIanaCountryCode(data.javaCountry), is(data.ianaCountry)); + } + } + public void testAddedVoices() { getVoices(); // Ensure that the voice data has been populated. diff --git a/android/src/com/reecedunn/espeak/SpeechSynthesis.java b/android/src/com/reecedunn/espeak/SpeechSynthesis.java index 481b8f70..17d93898 100644 --- a/android/src/com/reecedunn/espeak/SpeechSynthesis.java +++ b/android/src/com/reecedunn/espeak/SpeechSynthesis.java @@ -320,7 +320,7 @@ public class SpeechSynthesis { final Configuration config = context.getResources().getConfiguration(); final String language = getIanaLanguageCode(locale.getLanguage()); - final String country = getIanaLocaleCode(locale.getCountry(), mJavaToIanaCountryCode); + final String country = getIanaCountryCode(locale.getCountry()); config.locale = new Locale(language, country, locale.getVariant()); Resources res = new Resources(context.getAssets(), metrics, config); @@ -371,6 +371,10 @@ public class SpeechSynthesis { return getIanaLocaleCode(code, mJavaToIanaLanguageCode); } + public static String getIanaCountryCode(String code) { + return getIanaLocaleCode(code, mJavaToIanaCountryCode); + } + private static String getIanaLocaleCode(String code, final Map javaToIana) { final String iana = javaToIana.get(code); if (iana != null) { @@ -449,12 +453,13 @@ public class SpeechSynthesis { mJavaToIanaLanguageCode.put("vie", "vi"); mJavaToIanaLanguageCode.put("zho", "zh"); - mJavaToIanaCountryCode.put("JAM", "JM"); - mJavaToIanaCountryCode.put("MEX", "MX"); mJavaToIanaCountryCode.put("BEL", "BE"); mJavaToIanaCountryCode.put("BRA", "BR"); mJavaToIanaCountryCode.put("FRA", "FR"); mJavaToIanaCountryCode.put("GBR", "GB"); + mJavaToIanaCountryCode.put("HKG", "HK"); + mJavaToIanaCountryCode.put("JAM", "JM"); + mJavaToIanaCountryCode.put("MEX", "MX"); mJavaToIanaCountryCode.put("PRT", "PT"); mJavaToIanaCountryCode.put("USA", "US"); mJavaToIanaCountryCode.put("VNM", "VN");