Browse Source

TtsService: set the language properties to the matched voice, not the requested voice

master
Reece H. Dunn 12 years ago
parent
commit
7816a0a204

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

@@ -101,13 +101,13 @@ public class TextToSpeechTest extends AndroidTestCase
assertThat(mEngine.setLanguage(iana2), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(mEngine.getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(mEngine.getLanguage().getCountry(), is(data.javaCountry));
assertThat(mEngine.getLanguage().getVariant(), is("test"));
assertThat(mEngine.getLanguage().getVariant(), is(""));

assertThat(mEngine.isLanguageAvailable(iana3), is(TextToSpeech.LANG_AVAILABLE));
assertThat(mEngine.setLanguage(iana3), is(TextToSpeech.LANG_AVAILABLE));
assertThat(mEngine.getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(mEngine.getLanguage().getCountry(), is("VUT"));
assertThat(mEngine.getLanguage().getVariant(), is(data.variant));
assertThat(mEngine.getLanguage().getCountry(), is(""));
assertThat(mEngine.getLanguage().getVariant(), is(""));

assertThat(mEngine.isLanguageAvailable(java1), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(mEngine.setLanguage(java1), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
@@ -119,13 +119,13 @@ public class TextToSpeechTest extends AndroidTestCase
assertThat(mEngine.setLanguage(java2), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(mEngine.getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(mEngine.getLanguage().getCountry(), is(data.javaCountry));
assertThat(mEngine.getLanguage().getVariant(), is("test"));
assertThat(mEngine.getLanguage().getVariant(), is(""));

assertThat(mEngine.isLanguageAvailable(java3), is(TextToSpeech.LANG_AVAILABLE));
assertThat(mEngine.setLanguage(java3), is(TextToSpeech.LANG_AVAILABLE));
assertThat(mEngine.getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(mEngine.getLanguage().getCountry(), is("VUT"));
assertThat(mEngine.getLanguage().getVariant(), is(data.variant));
assertThat(mEngine.getLanguage().getCountry(), is(""));
assertThat(mEngine.getLanguage().getVariant(), is(""));
}
catch (Exception e)
{

+ 26
- 13
android/src/com/reecedunn/espeak/TtsService.java View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 Google Inc.
* Copyright (C) 2012 Reece H. Dunn
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,6 +48,7 @@ import java.util.Locale;
/**
* Implements the eSpeak engine as a {@link TextToSpeechService}.
*
* @author [email protected] (Reece H. Dunn)
* @author [email protected] (Alan Viverette)
*/
@SuppressLint("NewApi")
@@ -152,20 +153,32 @@ public class TtsService extends TextToSpeechService {
@Override
protected int onLoadLanguage(String language, String country, String variant) {
final int result = onIsLanguageAvailable(language, country, variant);

// Return immediately if the language is not available.
if (result == TextToSpeech.LANG_NOT_SUPPORTED) {
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;
default:
Log.e(TAG, "Failed to load language {language='" + language + "', country='" + country
+ "', variant='" + variant + "'");
return result;
+ "', variant='" + variant + "'}, result=" + result);
}

synchronized (this) {
mLanguage = language;
mCountry = ((country == null) ? "" : country);
mVariant = ((variant == null) ? "" : variant);
}

return result;
}


Loading…
Cancel
Save