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

assertThat(mEngine.setLanguage(iana2), is(TextToSpeech.LANG_COUNTRY_AVAILABLE)); assertThat(mEngine.setLanguage(iana2), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(mEngine.getLanguage().getLanguage(), is(data.javaLanguage)); assertThat(mEngine.getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(mEngine.getLanguage().getCountry(), is(data.javaCountry)); 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.isLanguageAvailable(iana3), is(TextToSpeech.LANG_AVAILABLE));
assertThat(mEngine.setLanguage(iana3), is(TextToSpeech.LANG_AVAILABLE)); assertThat(mEngine.setLanguage(iana3), is(TextToSpeech.LANG_AVAILABLE));
assertThat(mEngine.getLanguage().getLanguage(), is(data.javaLanguage)); 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.isLanguageAvailable(java1), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(mEngine.setLanguage(java1), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE)); assertThat(mEngine.setLanguage(java1), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(mEngine.setLanguage(java2), is(TextToSpeech.LANG_COUNTRY_AVAILABLE)); assertThat(mEngine.setLanguage(java2), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(mEngine.getLanguage().getLanguage(), is(data.javaLanguage)); assertThat(mEngine.getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(mEngine.getLanguage().getCountry(), is(data.javaCountry)); 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.isLanguageAvailable(java3), is(TextToSpeech.LANG_AVAILABLE));
assertThat(mEngine.setLanguage(java3), is(TextToSpeech.LANG_AVAILABLE)); assertThat(mEngine.setLanguage(java3), is(TextToSpeech.LANG_AVAILABLE));
assertThat(mEngine.getLanguage().getLanguage(), is(data.javaLanguage)); 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) catch (Exception e)
{ {

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

/* /*
* Copyright (C) 2011 Google Inc.
* Copyright (C) 2012 Reece H. Dunn * Copyright (C) 2012 Reece H. Dunn
* Copyright (C) 2011 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
/** /**
* Implements the eSpeak engine as a {@link TextToSpeechService}. * Implements the eSpeak engine as a {@link TextToSpeechService}.
* *
* @author [email protected] (Reece H. Dunn)
* @author [email protected] (Alan Viverette) * @author [email protected] (Alan Viverette)
*/ */
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Override @Override
protected int onLoadLanguage(String language, String country, String variant) { protected int onLoadLanguage(String language, String country, String variant) {
final int result = onIsLanguageAvailable(language, country, 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 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; return result;
} }



Loading…
Cancel
Save