SpeechSynthesis: factor out the Voice class into its own file.

This commit is contained in:
Reece H. Dunn
2013-05-09 13:56:02 +01:00
parent 774c909a9c
commit 7ee59ed331
5 changed files with 68 additions and 49 deletions
@@ -27,7 +27,6 @@ package com.reecedunn.espeak;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.speech.tts.TextToSpeech;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -345,51 +344,6 @@ public class SpeechSynthesis {
void onSynthDataComplete();
}
public class Voice {
public final String name;
public final String identifier;
public final int gender;
public final int age;
public final Locale locale;
public Voice(String name, String identifier, int gender, int age, Locale locale) {
this.name = name;
this.identifier = identifier;
this.gender = gender;
this.age = age;
this.locale = locale;
}
/**
* Attempts a partial match against a query locale.
*
* @param query The locale to match.
* @return A text-to-speech availability code. One of:
* <ul>
* <li>{@link TextToSpeech#LANG_NOT_SUPPORTED}
* <li>{@link TextToSpeech#LANG_AVAILABLE}
* <li>{@link TextToSpeech#LANG_COUNTRY_AVAILABLE}
* <li>{@link TextToSpeech#LANG_COUNTRY_VAR_AVAILABLE}
* </ul>
*/
public int match(Locale query) {
if (!locale.getISO3Language().equals(query.getISO3Language())) {
return TextToSpeech.LANG_NOT_SUPPORTED;
} else if (!locale.getISO3Country().equals(query.getISO3Country())) {
return TextToSpeech.LANG_AVAILABLE;
} else if (!locale.getVariant().equals(query.getVariant())) {
return TextToSpeech.LANG_COUNTRY_AVAILABLE;
} else {
return TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE;
}
}
@Override
public String toString() {
return locale.toString().replace('_', '-');
}
}
private static String getIanaLocaleCode(String code, final Map<String, String> javaToIana) {
final String iana = javaToIana.get(code);
if (iana != null) {