mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-10-31 13:38:47 +00:00
This creates a custom hamcrest matcher that maps the TextToSpeech LANG_* constants to strings. This makes it easier to read the text output when the tests fail.
109 lines
5.6 KiB
Java
109 lines
5.6 KiB
Java
/*
|
|
* Copyright (C) 2012-2013 Reece H. Dunn
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package com.reecedunn.espeak.test;
|
|
|
|
import java.util.Locale;
|
|
|
|
import android.speech.tts.TextToSpeech;
|
|
|
|
import static com.reecedunn.espeak.test.TtsMatcher.isTtsLangCode;
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
import static org.hamcrest.Matchers.*;
|
|
|
|
public class TextToSpeechTest extends TextToSpeechTestCase
|
|
{
|
|
public void testUnsupportedLanguage()
|
|
{
|
|
assertThat(getEngine(), is(notNullValue()));
|
|
|
|
Locale initialLocale = getEngine().getLanguage();
|
|
assertThat(getEngine().isLanguageAvailable(new Locale("cel")), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
|
|
assertThat(getEngine().getLanguage().getLanguage(), is(initialLocale.getLanguage()));
|
|
assertThat(getEngine().getLanguage().getCountry(), is(initialLocale.getCountry()));
|
|
assertThat(getEngine().getLanguage().getVariant(), is(initialLocale.getVariant()));
|
|
}
|
|
|
|
public void testLanguages()
|
|
{
|
|
assertThat(getEngine(), is(notNullValue()));
|
|
|
|
for (VoiceData.Voice data : VoiceData.voices)
|
|
{
|
|
String context = null;
|
|
try
|
|
{
|
|
// Skip the voice if the language code is not supported by Android:
|
|
if (data.javaLanguage.equals("")) continue;
|
|
|
|
final Locale iana1 = new Locale(data.ianaLanguage, data.ianaCountry, data.variant);
|
|
final Locale iana2 = new Locale(data.ianaLanguage, data.ianaCountry, "test");
|
|
final Locale iana3 = new Locale(data.ianaLanguage, "VU", data.variant);
|
|
|
|
final Locale java1 = new Locale(data.javaLanguage, data.javaCountry, data.variant);
|
|
final Locale java2 = new Locale(data.javaLanguage, data.javaCountry, "test");
|
|
final Locale java3 = new Locale(data.javaLanguage, "VUT", data.variant);
|
|
|
|
context = "iana1";
|
|
assertThat(getEngine().isLanguageAvailable(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
|
|
assertThat(getEngine().setLanguage(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
|
|
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
|
|
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
|
|
assertThat(getEngine().getLanguage().getVariant(), is(data.variant));
|
|
|
|
context = "iana2";
|
|
assertThat(getEngine().isLanguageAvailable(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
|
|
assertThat(getEngine().setLanguage(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
|
|
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
|
|
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
|
|
assertThat(getEngine().getLanguage().getVariant(), is(""));
|
|
|
|
context = "iana3";
|
|
assertThat(getEngine().isLanguageAvailable(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
|
|
assertThat(getEngine().setLanguage(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
|
|
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
|
|
assertThat(getEngine().getLanguage().getCountry(), is(""));
|
|
assertThat(getEngine().getLanguage().getVariant(), is(""));
|
|
|
|
context = "java1";
|
|
assertThat(getEngine().isLanguageAvailable(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
|
|
assertThat(getEngine().setLanguage(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
|
|
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
|
|
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
|
|
assertThat(getEngine().getLanguage().getVariant(), is(data.variant));
|
|
|
|
context = "java2";
|
|
assertThat(getEngine().isLanguageAvailable(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
|
|
assertThat(getEngine().setLanguage(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
|
|
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
|
|
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
|
|
assertThat(getEngine().getLanguage().getVariant(), is(""));
|
|
|
|
context = "java3";
|
|
assertThat(getEngine().isLanguageAvailable(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
|
|
assertThat(getEngine().setLanguage(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
|
|
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
|
|
assertThat(getEngine().getLanguage().getCountry(), is(""));
|
|
assertThat(getEngine().getLanguage().getVariant(), is(""));
|
|
}
|
|
catch (AssertionError e)
|
|
{
|
|
throw new VoiceData.Exception(data, context, e);
|
|
}
|
|
}
|
|
}
|
|
}
|