| import android.speech.tts.TextToSpeech; | import android.speech.tts.TextToSpeech; | ||||
| import android.speech.tts.TextToSpeech.OnInitListener; | import android.speech.tts.TextToSpeech.OnInitListener; | ||||
| import android.test.AndroidTestCase; | import android.test.AndroidTestCase; | ||||
| import android.util.Log; | |||||
| import java.util.Locale; | |||||
| import static org.hamcrest.MatcherAssert.assertThat; | import static org.hamcrest.MatcherAssert.assertThat; | ||||
| import static org.hamcrest.Matchers.*; | import static org.hamcrest.Matchers.*; | ||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| // Wait until the text-to-speech engine is initialised: | |||||
| // Wait until the text-to-speech engine is initialised (max: 5 seconds): | |||||
| mEngine = new TextToSpeech(getContext(), mInitCallback); | mEngine = new TextToSpeech(getContext(), mInitCallback); | ||||
| for (int count = 0; !mInitialised && count < 20; ++count) | for (int count = 0; !mInitialised && count < 20; ++count) | ||||
| { | { | ||||
| assertThat(mInitialised, is(true)); | assertThat(mInitialised, is(true)); | ||||
| assertThat(mStatus, is(TextToSpeech.SUCCESS)); | assertThat(mStatus, is(TextToSpeech.SUCCESS)); | ||||
| assertThat(mEngine.getDefaultEngine(), is("com.reecedunn.espeak")); | assertThat(mEngine.getDefaultEngine(), is("com.reecedunn.espeak")); | ||||
| // Ensure that the voice data is installed (max: 20 seconds): | |||||
| Locale en = new Locale("en"); | |||||
| int available = mEngine.isLanguageAvailable(en); | |||||
| for (int count = 0; available != TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE && count < (4 * 20); ++count) | |||||
| { | |||||
| Thread.sleep(250); | |||||
| available = mEngine.isLanguageAvailable(en); | |||||
| Log.d("TextToSpeechTestCase", "setUp: available = " + available); | |||||
| } | |||||
| assertThat(available, is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE)); | |||||
| } | } | ||||
| catch (Exception e) | catch (Exception e) | ||||
| { | { |