mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-10-31 13:38:47 +00:00
TtsService: only set mMatchingVoice when told to load the voice.
This commit is contained in:
@@ -108,16 +108,17 @@ public class TextToSpeechServiceTest extends AndroidTestCase
|
||||
assertThat(mService.onLoadLanguage("eng", "FRA", "rp"), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
|
||||
checkLanguage(mService.onGetLanguage(), "eng", "", "");
|
||||
assertThat(mService.getActiveVoice(), is(notNullValue()));
|
||||
assertThat(mService.getActiveVoice().name, is("en-uk-rp"));
|
||||
assertThat(mService.getActiveVoice().name, is("en"));
|
||||
|
||||
assertThat(mService.onLoadLanguage("eng", "FRA", ""), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
|
||||
checkLanguage(mService.onGetLanguage(), "eng", "", "");
|
||||
assertThat(mService.getActiveVoice(), is(notNullValue()));
|
||||
assertThat(mService.getActiveVoice().name, is("en-uk-rp"));
|
||||
assertThat(mService.getActiveVoice().name, is("en"));
|
||||
|
||||
assertThat(mService.onLoadLanguage("ine", "", ""), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
|
||||
checkLanguage(mService.onGetLanguage(), "eng", "", "");
|
||||
assertThat(mService.getActiveVoice(), is(nullValue()));
|
||||
assertThat(mService.getActiveVoice(), is(notNullValue()));
|
||||
assertThat(mService.getActiveVoice().name, is("en"));
|
||||
}
|
||||
|
||||
public void testOnIsLanguageAvailable() {
|
||||
@@ -126,41 +127,42 @@ public class TextToSpeechServiceTest extends AndroidTestCase
|
||||
assertThat(mService.onIsLanguageAvailable("eng", "", ""), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
|
||||
checkLanguage(mService.onGetLanguage(), "vie", "VNM", "saigon");
|
||||
assertThat(mService.getActiveVoice(), is(notNullValue()));
|
||||
assertThat(mService.getActiveVoice().name, is("en"));
|
||||
assertThat(mService.getActiveVoice().name, is("vi-sgn"));
|
||||
|
||||
assertThat(mService.onIsLanguageAvailable("eng", "USA", ""), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
|
||||
checkLanguage(mService.onGetLanguage(), "vie", "VNM", "saigon");
|
||||
assertThat(mService.getActiveVoice(), is(notNullValue()));
|
||||
assertThat(mService.getActiveVoice().name, is("en-us"));
|
||||
assertThat(mService.getActiveVoice().name, is("vi-sgn"));
|
||||
|
||||
assertThat(mService.onIsLanguageAvailable("eng", "GBR", "scotland"), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
|
||||
checkLanguage(mService.onGetLanguage(), "vie", "VNM", "saigon");
|
||||
assertThat(mService.getActiveVoice(), is(notNullValue()));
|
||||
assertThat(mService.getActiveVoice().name, is("en-sc"));
|
||||
assertThat(mService.getActiveVoice().name, is("vi-sgn"));
|
||||
|
||||
assertThat(mService.onIsLanguageAvailable("eng", "USA", "rp"), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
|
||||
checkLanguage(mService.onGetLanguage(), "vie", "VNM", "saigon");
|
||||
assertThat(mService.getActiveVoice(), is(notNullValue()));
|
||||
assertThat(mService.getActiveVoice().name, is("en-us"));
|
||||
assertThat(mService.getActiveVoice().name, is("vi-sgn"));
|
||||
|
||||
assertThat(mService.onIsLanguageAvailable("eng", "", "scotland"), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
|
||||
checkLanguage(mService.onGetLanguage(), "vie", "VNM", "saigon");
|
||||
assertThat(mService.getActiveVoice(), is(notNullValue()));
|
||||
assertThat(mService.getActiveVoice().name, is("en"));
|
||||
assertThat(mService.getActiveVoice().name, is("vi-sgn"));
|
||||
|
||||
assertThat(mService.onIsLanguageAvailable("eng", "FRA", "rp"), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
|
||||
checkLanguage(mService.onGetLanguage(), "vie", "VNM", "saigon");
|
||||
assertThat(mService.getActiveVoice(), is(notNullValue()));
|
||||
assertThat(mService.getActiveVoice().name, is("en-uk-rp"));
|
||||
assertThat(mService.getActiveVoice().name, is("vi-sgn"));
|
||||
|
||||
assertThat(mService.onIsLanguageAvailable("eng", "FRA", ""), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
|
||||
checkLanguage(mService.onGetLanguage(), "vie", "VNM", "saigon");
|
||||
assertThat(mService.getActiveVoice(), is(notNullValue()));
|
||||
assertThat(mService.getActiveVoice().name, is("en-uk-rp"));
|
||||
assertThat(mService.getActiveVoice().name, is("vi-sgn"));
|
||||
|
||||
assertThat(mService.onIsLanguageAvailable("ine", "", ""), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
|
||||
checkLanguage(mService.onGetLanguage(), "vie", "VNM", "saigon");
|
||||
assertThat(mService.getActiveVoice(), is(nullValue()));
|
||||
assertThat(mService.getActiveVoice(), is(notNullValue()));
|
||||
assertThat(mService.getActiveVoice().name, is("vi-sgn"));
|
||||
}
|
||||
|
||||
public void testOnGetDefaultVoiceNameFor() {
|
||||
|
||||
@@ -61,10 +61,6 @@ public class TtsService extends TextToSpeechService {
|
||||
private static final String TAG = TtsService.class.getSimpleName();
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private static final String DEFAULT_LANGUAGE = "en";
|
||||
private static final String DEFAULT_COUNTRY = "uk";
|
||||
private static final String DEFAULT_VARIANT = "";
|
||||
|
||||
private SpeechSynthesis mEngine;
|
||||
private SynthesisCallback mCallback;
|
||||
|
||||
@@ -73,10 +69,6 @@ public class TtsService extends TextToSpeechService {
|
||||
|
||||
private BroadcastReceiver mOnLanguagesDownloaded = null;
|
||||
|
||||
private String mLanguage = DEFAULT_LANGUAGE;
|
||||
private String mCountry = DEFAULT_COUNTRY;
|
||||
private String mVariant = DEFAULT_VARIANT;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
initializeTtsEngine();
|
||||
@@ -112,8 +104,13 @@ public class TtsService extends TextToSpeechService {
|
||||
@Override
|
||||
protected String[] onGetLanguage() {
|
||||
// This is used to specify the language requested from GetSampleText.
|
||||
if (mMatchingVoice == null) {
|
||||
return new String[] { "eng", "GBR", "" };
|
||||
}
|
||||
return new String[] {
|
||||
mLanguage, mCountry, mVariant
|
||||
mMatchingVoice.locale.getISO3Language(),
|
||||
mMatchingVoice.locale.getISO3Country(),
|
||||
mMatchingVoice.locale.getVariant()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -180,42 +177,16 @@ public class TtsService extends TextToSpeechService {
|
||||
|
||||
@Override
|
||||
protected int onIsLanguageAvailable(String language, String country, String variant) {
|
||||
final Pair<Voice, Integer> match = findVoice(language, country, variant);
|
||||
mMatchingVoice = match.first;
|
||||
return match.second;
|
||||
return findVoice(language, country, variant).second;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int onLoadLanguage(String language, String country, String variant) {
|
||||
final int result = onIsLanguageAvailable(language, country, variant);
|
||||
switch (result) {
|
||||
case TextToSpeech.LANG_AVAILABLE:
|
||||
synchronized (this) {
|
||||
mLanguage = language;
|
||||
mCountry = "";
|
||||
mVariant = "";
|
||||
}
|
||||
break;
|
||||
case TextToSpeech.LANG_COUNTRY_AVAILABLE:
|
||||
synchronized (this) {
|
||||
mLanguage = language;
|
||||
mCountry = ((country == null) ? "" : country);
|
||||
mVariant = "";
|
||||
}
|
||||
break;
|
||||
case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE:
|
||||
synchronized (this) {
|
||||
mLanguage = language;
|
||||
mCountry = ((country == null) ? "" : country);
|
||||
mVariant = ((variant == null) ? "" : variant);
|
||||
}
|
||||
break;
|
||||
case TextToSpeech.LANG_NOT_SUPPORTED:
|
||||
Log.e(TAG, "Unsupported language {language='" + language + "', country='" + country
|
||||
+ "', variant='" + variant + "'}");
|
||||
break;
|
||||
final Pair<Voice, Integer> match = getDefaultVoiceFor(language, country, variant);
|
||||
if (match.first != null) {
|
||||
mMatchingVoice = match.first;
|
||||
}
|
||||
return result;
|
||||
return match.second;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user