Search in sources :

Example 26 with TextToSpeech

use of android.speech.tts.TextToSpeech in project robolectric by robolectric.

the class ShadowTextToSpeechTest method isStopped_shouldReturnTrueAfterStop.

@Test
public void isStopped_shouldReturnTrueAfterStop() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    textToSpeech.stop();
    assertThat(shadowOf(textToSpeech).isStopped()).isTrue();
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test)

Example 27 with TextToSpeech

use of android.speech.tts.TextToSpeech in project robolectric by robolectric.

the class ShadowTextToSpeechTest method isStopped_shouldReturnTrueBeforeSpeak.

@Test
public void isStopped_shouldReturnTrueBeforeSpeak() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    assertThat(shadowOf(textToSpeech).isStopped()).isTrue();
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test)

Example 28 with TextToSpeech

use of android.speech.tts.TextToSpeech in project robolectric by robolectric.

the class ShadowTextToSpeechTest method isLanguageAvailable_matchingLanguage_returnsLangAvailable.

@Test
public void isLanguageAvailable_matchingLanguage_returnsLangAvailable() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    ShadowTextToSpeech.addLanguageAvailability(new Locale.Builder().setLanguage("en").setRegion("us").build());
    assertThat(textToSpeech.isLanguageAvailable(new Locale.Builder().setLanguage("en").setRegion("gb").build())).isEqualTo(TextToSpeech.LANG_AVAILABLE);
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test)

Example 29 with TextToSpeech

use of android.speech.tts.TextToSpeech in project robolectric by robolectric.

the class ShadowTextToSpeechTest method threeArgumentSpeak_withUtteranceId_shouldGetCallbackUtteranceId.

@Test
public void threeArgumentSpeak_withUtteranceId_shouldGetCallbackUtteranceId() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    UtteranceProgressListener mockListener = mock(UtteranceProgressListener.class);
    textToSpeech.setOnUtteranceProgressListener(mockListener);
    HashMap<String, String> paramsMap = new HashMap<>();
    paramsMap.put(Engine.KEY_PARAM_UTTERANCE_ID, "ThreeArgument");
    textToSpeech.speak("Hello", TextToSpeech.QUEUE_FLUSH, paramsMap);
    shadowMainLooper().idle();
    verify(mockListener).onStart("ThreeArgument");
    verify(mockListener).onDone("ThreeArgument");
}
Also used : HashMap(java.util.HashMap) UtteranceProgressListener(android.speech.tts.UtteranceProgressListener) TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test)

Example 30 with TextToSpeech

use of android.speech.tts.TextToSpeech in project robolectric by robolectric.

the class ShadowTextToSpeechTest method clearLastSpokenText_shouldSetLastSpokenTextToNull.

@Test
public void clearLastSpokenText_shouldSetLastSpokenTextToNull() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    textToSpeech.speak("Hello", TextToSpeech.QUEUE_FLUSH, null);
    shadowOf(textToSpeech).clearLastSpokenText();
    assertThat(shadowOf(textToSpeech).getLastSpokenText()).isNull();
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test)

Aggregations

TextToSpeech (android.speech.tts.TextToSpeech)103 Test (org.junit.Test)34 Locale (java.util.Locale)18 TtsEngines (android.speech.tts.TtsEngines)15 ActivityNotFoundException (android.content.ActivityNotFoundException)12 Intent (android.content.Intent)12 ContentResolver (android.content.ContentResolver)10 MissingResourceException (java.util.MissingResourceException)10 IntentFilter (android.content.IntentFilter)8 TextView (android.widget.TextView)7 Config (org.robolectric.annotation.Config)7 BluetoothAdapter (android.bluetooth.BluetoothAdapter)6 Handler (android.os.Handler)6 UtteranceProgressListener (android.speech.tts.UtteranceProgressListener)6 ArrayAdapter (android.widget.ArrayAdapter)6 Context (android.content.Context)5 HashMap (java.util.HashMap)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Bundle (android.os.Bundle)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3