Browse Source

TtsService: fix and test onGetVoice.

The default Android 5.0 implementation enumerates the available
locales. This enumerates the voices returned by eSpeak.
master
Reece H. Dunn 10 years ago
parent
commit
f9912e0c41

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



package com.reecedunn.espeak.test; package com.reecedunn.espeak.test;


import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Set;


import android.annotation.SuppressLint;
import android.os.Build;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;


import static com.reecedunn.espeak.test.TtsMatcher.isTtsLangCode; import static com.reecedunn.espeak.test.TtsMatcher.isTtsLangCode;


public class TextToSpeechTest extends TextToSpeechTestCase public class TextToSpeechTest extends TextToSpeechTestCase
{ {
private Set<Object> mVoices = null;
private Set<String> mAdded = new HashSet<String>();
private Set<String> mRemoved = new HashSet<String>();

@SuppressLint("NewApi")
public Set<Object> getVoices()
{
if (mVoices == null)
{
Set<android.speech.tts.Voice> voiceData = getEngine().getVoices();
assertThat(voiceData, is(notNullValue()));

mVoices = new HashSet<Object>();
for (android.speech.tts.Voice voice : voiceData)
{
mVoices.add(voice);
}

Set<String> voices = new HashSet<String>();
for (Object data : mVoices)
{
voices.add(((android.speech.tts.Voice)data).getName());
}

Set<String> expected = new HashSet<String>();
for (VoiceData.Voice data : VoiceData.voices)
{
expected.add(data.name);
}

for (String voice : voices)
{
if (!expected.contains(voice))
{
mAdded.add(voice);
}
}

for (String voice : expected)
{
if (!voices.contains(voice))
{
mRemoved.add(voice);
}
}
}
return mVoices;
}

public void testAddedVoices()
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
return;

getVoices(); // Ensure that the voice data has been populated.
assertThat(mAdded.toString(), is("[]"));
}

public void testRemovedVoices()
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
return;

getVoices(); // Ensure that the voice data has been populated.
assertThat(mRemoved.toString(), is("[]"));
}

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

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



import com.reecedunn.espeak.SpeechSynthesis.SynthReadyCallback; import com.reecedunn.espeak.SpeechSynthesis.SynthReadyCallback;


import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;




@Override @Override
public List<android.speech.tts.Voice> onGetVoices() { public List<android.speech.tts.Voice> onGetVoices() {
return super.onGetVoices();
List<android.speech.tts.Voice> voices = new ArrayList<android.speech.tts.Voice>();
for (Voice voice : mAvailableVoices) {
int quality = android.speech.tts.Voice.QUALITY_NORMAL;
int latency = android.speech.tts.Voice.LATENCY_VERY_LOW;
voices.add(new android.speech.tts.Voice(voice.name, voice.locale, quality, latency, false, null));
}
return voices;
} }


@Override @Override

Loading…
Cancel
Save