Search in sources :

Example 36 with TextToSpeech

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

the class ShadowTextToSpeechTest method threeArgumentSpeak_withoutUtteranceId_shouldDoesNotGetCallback.

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

Example 37 with TextToSpeech

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

the class ShadowTextToSpeechTest method shouldNotBeNull.

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

Example 38 with TextToSpeech

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

the class ShadowTextToSpeechTest method isStopped_shouldReturnFalseAfterSpeak.

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

Example 39 with TextToSpeech

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

the class ShadowTextToSpeechTest method isLanguageAvailable_twoLanguageAvailabilities_returnsRequestedAvailability.

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

Example 40 with TextToSpeech

use of android.speech.tts.TextToSpeech in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class TtsEnginePreferenceFragment method onUpdateEngine.

/**
 * Step 3: We have now bound to the TTS engine the user requested. We will attempt to check
 * voice data for the engine if we successfully bound to it, or revert to the previous engine if
 * we didn't.
 */
public void onUpdateEngine(int status) {
    if (status == TextToSpeech.SUCCESS) {
        Log.d(TAG, "Updating engine: Successfully bound to the engine: " + mTts.getCurrentEngine());
        android.provider.Settings.Secure.putString(getContentResolver(), TTS_DEFAULT_SYNTH, mTts.getCurrentEngine());
    } else {
        Log.d(TAG, "Updating engine: Failed to bind to engine, reverting.");
        if (mPreviousEngine != null) {
            // This is guaranteed to at least bind, since mPreviousEngine would be
            // null if the previous bind to this engine failed.
            mTts = new TextToSpeech(getActivity().getApplicationContext(), null, mPreviousEngine);
        }
        mPreviousEngine = null;
    }
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech)

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