|
|
@@ -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; |
|
|
|
} |
|
|
|
|
|
|
|
/** |