Search in sources :

Example 81 with TextToSpeech

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

the class ShadowTextToSpeechTest method getQueueMode_shouldReturnMostRecentQueueMode.

@Test
public void getQueueMode_shouldReturnMostRecentQueueMode() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    textToSpeech.speak("Hello", TextToSpeech.QUEUE_ADD, null);
    assertThat(shadowOf(textToSpeech).getQueueMode()).isEqualTo(TextToSpeech.QUEUE_ADD);
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test)

Example 82 with TextToSpeech

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

the class ShadowTextToSpeechTest method isLanguageAvailable_neverAdded_returnsUnsupported.

@Test
public void isLanguageAvailable_neverAdded_returnsUnsupported() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    assertThat(textToSpeech.isLanguageAvailable(new Locale.Builder().setLanguage("pl").setRegion("pl").build())).isEqualTo(TextToSpeech.LANG_NOT_SUPPORTED);
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test)

Example 83 with TextToSpeech

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

the class ShadowTextToSpeechTest method onInitListener_success_getsCalledAsynchronously.

@Test
public void onInitListener_success_getsCalledAsynchronously() {
    AtomicReference<Integer> onInitCalled = new AtomicReference<>();
    TextToSpeech.OnInitListener listener = onInitCalled::set;
    TextToSpeech textToSpeech = new TextToSpeech(activity, listener);
    assertThat(textToSpeech).isNotNull();
    Shadows.shadowOf(textToSpeech).getOnInitListener().onInit(TextToSpeech.SUCCESS);
    assertThat(onInitCalled.get()).isEqualTo(TextToSpeech.SUCCESS);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test)

Example 84 with TextToSpeech

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

the class ShadowTextToSpeechTest method onUtteranceProgressListener_shouldGetCallbackUtteranceId.

@Test
@Config(minSdk = LOLLIPOP)
public void onUtteranceProgressListener_shouldGetCallbackUtteranceId() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    UtteranceProgressListener mockListener = mock(UtteranceProgressListener.class);
    textToSpeech.setOnUtteranceProgressListener(mockListener);
    textToSpeech.speak("Hello", TextToSpeech.QUEUE_FLUSH, null, "TTSEnable");
    shadowMainLooper().idle();
    verify(mockListener).onStart("TTSEnable");
    verify(mockListener).onDone("TTSEnable");
}
Also used : UtteranceProgressListener(android.speech.tts.UtteranceProgressListener) TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 85 with TextToSpeech

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

the class ShadowTextToSpeechTest method synthesizeToFile_lastSynthesizeToFileTextStored.

@Test
@Config(minSdk = LOLLIPOP)
public void synthesizeToFile_lastSynthesizeToFileTextStored() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    Bundle bundle = new Bundle();
    File file = new File("example.txt");
    int result = textToSpeech.synthesizeToFile("text", bundle, file, "id");
    assertThat(result).isEqualTo(TextToSpeech.SUCCESS);
    assertThat(shadowOf(textToSpeech).getLastSynthesizeToFileText()).isEqualTo("text");
}
Also used : Bundle(android.os.Bundle) TextToSpeech(android.speech.tts.TextToSpeech) File(java.io.File) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

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