Browse Source

Do not add a voice if the Locale assigns a blank ISO3 language code.

master
Reece H. Dunn 12 years ago
parent
commit
f455a466c3

+ 2
- 2
android/eSpeakTests/src/com/reecedunn/espeak/test/SpeechSynthesisTest.java View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 Reece H. Dunn
* Copyright (C) 2012-2013 Reece H. Dunn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -206,7 +206,7 @@ public class SpeechSynthesisTest extends AndroidTestCase
public void testRemovedVoices()
{
getVoices(); // Ensure that the voice data has been populated.
assertThat(mRemoved.toString(), is("[]"));
assertThat(mRemoved.toString(), is("[nci, prs]"));
}

public void testVoiceData()

+ 4
- 1
android/eSpeakTests/src/com/reecedunn/espeak/test/TextToSpeechTest.java View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 Reece H. Dunn
* Copyright (C) 2012-2013 Reece H. Dunn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -93,6 +93,9 @@ public class TextToSpeechTest extends AndroidTestCase
{
try
{
// Skip the voice if the language code is not supported by Android:
if (data.javaLanguage.equals("")) continue;

final Locale iana1 = new Locale(data.ianaLanguage, data.ianaCountry, data.variant);
final Locale iana2 = new Locale(data.ianaLanguage, data.ianaCountry, "test");
final Locale iana3 = new Locale(data.ianaLanguage, "VU", data.variant);

+ 46
- 43
android/src/com/reecedunn/espeak/SpeechSynthesis.java View File

@@ -109,9 +109,51 @@ public class SpeechSynthesis {
final String identifier = results[i + 1];
final int gender = Integer.parseInt(results[i + 2]);
final int age = Integer.parseInt(results[i + 3]);
final Voice voice = new Voice(name, identifier, gender, age);
final Locale locale;
if (name.equals("en-sc")) {
// 'SC' is not a country code.
locale = new Locale("en", "GB", "scotland");
} else if (name.equals("en-wi")) {
// 'WI' is not a country code.
locale = new Locale("en", "029");
} else if (name.equals("es-la")) {
// 'LA' is the country code for Laos, not Latin America.
locale = new Locale("es", "419");
} else if (name.equals("hy-west")) {
// 'west' is not a country code.
locale = new Locale("hy", "", "arevmda");
} else if (name.equals("zh-yue")) {
// Android/Java does not support macrolanguages.
locale = new Locale("zh", "HK");
} else {
String[] parts = name.split("-");
switch (parts.length) {
case 1: // language
locale = new Locale(parts[0]);
break;
case 2: // language-country
if (parts[1].equals("uk")) {
// 'uk' is the language code for Ukranian, not Great Britain.
parts[1] = "GB";
}
locale = new Locale(parts[0], parts[1]);
break;
case 3: // language-country-variant
if (parts[1].equals("uk")) {
// 'uk' is the language code for Ukranian, not Great Britain.
parts[1] = "GB";
}
locale = new Locale(parts[0], parts[1], parts[2]);
break;
default:
locale = null;
}
}

voices.add(voice);
if (locale != null && !locale.getISO3Language().equals("")) {
final Voice voice = new Voice(name, identifier, gender, age, locale);
voices.add(voice);
}
}

return voices;
@@ -225,51 +267,12 @@ public class SpeechSynthesis {
public final int age;
public final Locale locale;

public Voice(String name, String identifier, int gender, int age) {
public Voice(String name, String identifier, int gender, int age, Locale locale) {
this.name = name;
this.identifier = identifier;
this.gender = gender;
this.age = age;

if (name.equals("en-sc")) {
// 'SC' is not a country code.
locale = new Locale("en", "GB", "scotland");
} else if (name.equals("en-wi")) {
// 'WI' is not a country code.
locale = new Locale("en", "029");
} else if (name.equals("es-la")) {
// 'LA' is the country code for Laos, not Latin America.
locale = new Locale("es", "419");
} else if (name.equals("hy-west")) {
// 'west' is not a country code.
locale = new Locale("hy", "", "arevmda");
} else if (name.equals("zh-yue")) {
// Android/Java does not support macrolanguages.
locale = new Locale("zh", "HK");
} else {
String[] parts = name.split("-");
switch (parts.length) {
case 1: // language
locale = new Locale(parts[0]);
break;
case 2: // language-country
if (parts[1].equals("uk")) {
// 'uk' is the language code for Ukranian, not Great Britain.
parts[1] = "GB";
}
locale = new Locale(parts[0], parts[1]);
break;
case 3: // language-country-variant
if (parts[1].equals("uk")) {
// 'uk' is the language code for Ukranian, not Great Britain.
parts[1] = "GB";
}
locale = new Locale(parts[0], parts[1], parts[2]);
break;
default:
locale = null;
}
}
this.locale = locale;
}

/**

Loading…
Cancel
Save