Browse Source

TextToSpeech: test and fix onIsValidVoiceName

master
Reece H. Dunn 10 years ago
parent
commit
c9003c50ba

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

@@ -79,6 +79,18 @@ public class TextToSpeechTest extends TextToSpeechTestCase
return mVoices;
}

public VoiceData.Voice getVoiceData(String name)
{
for (VoiceData.Voice voice : VoiceData.voices)
{
if (voice.name.equals(name))
{
return voice;
}
}
return null;
}

public void testAddedVoices()
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
@@ -97,6 +109,41 @@ public class TextToSpeechTest extends TextToSpeechTestCase
assertThat(mRemoved.toString(), is("[]"));
}

@SuppressLint("NewApi")
public void testVoices()
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
return;

getVoices(); // Ensure that the voice data has been populated.
for (Object item : mVoices)
{
android.speech.tts.Voice voice = (android.speech.tts.Voice)item;
VoiceData.Voice data = getVoiceData(voice.getName());

assertThat(data, is(notNullValue()));
assertThat(voice.getName(), is(data.name));
assertThat(voice.getLocale().getLanguage(), is(data.ianaLanguage));
assertThat(voice.getLocale().getCountry(), is(data.ianaCountry));
assertThat(voice.getLocale().getVariant(), is(data.variant));
assertThat(voice.getFeatures(), is(nullValue()));
assertThat(voice.getLatency(), is(android.speech.tts.Voice.LATENCY_VERY_LOW));
assertThat(voice.getQuality(), is(android.speech.tts.Voice.QUALITY_NORMAL));

getEngine().setVoice(voice);

android.speech.tts.Voice voice2 = getEngine().getVoice();
assertThat(voice2, is(notNullValue()));
assertThat(voice2.getName(), is(data.name));
assertThat(voice2.getLocale().getLanguage(), is(data.ianaLanguage));
assertThat(voice2.getLocale().getCountry(), is(data.ianaCountry));
assertThat(voice2.getLocale().getVariant(), is(data.variant));
assertThat(voice2.getFeatures(), is(nullValue()));
assertThat(voice2.getLatency(), is(android.speech.tts.Voice.LATENCY_VERY_LOW));
assertThat(voice2.getQuality(), is(android.speech.tts.Voice.QUALITY_NORMAL));
}
}

public void testUnsupportedLanguage()
{
assertThat(getEngine(), is(notNullValue()));

+ 6
- 1
android/src/com/reecedunn/espeak/TtsService.java View File

@@ -217,7 +217,12 @@ public class TtsService extends TextToSpeechService {

@Override
public int onIsValidVoiceName(String name) {
return super.onIsValidVoiceName(name);
for (Voice voice : mAvailableVoices) {
if (voice.name.equals(name)) {
return TextToSpeech.SUCCESS;
}
}
return TextToSpeech.ERROR;
}

@Override

Loading…
Cancel
Save