Search in sources :

Example 1 with Voice

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

the class ShadowTextToSpeechTest method getCurrentVoice_voiceSet_returnsVoice.

@Test
@Config(minSdk = LOLLIPOP)
public void getCurrentVoice_voiceSet_returnsVoice() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    Voice voice = new Voice("test voice", Locale.getDefault(), Voice.QUALITY_VERY_HIGH, Voice.LATENCY_LOW, false, /* requiresNetworkConnection */
    ImmutableSet.of());
    textToSpeech.setVoice(voice);
    assertThat(shadowOf(textToSpeech).getCurrentVoice()).isEqualTo(voice);
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech) Voice(android.speech.tts.Voice) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 2 with Voice

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

the class ShadowTextToSpeechTest method getVoices_returnsAvailableVoices.

@Test
@Config(minSdk = LOLLIPOP)
public void getVoices_returnsAvailableVoices() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    Voice voice = new Voice("test voice", Locale.getDefault(), Voice.QUALITY_VERY_HIGH, Voice.LATENCY_LOW, false, /* requiresNetworkConnection */
    ImmutableSet.of());
    ShadowTextToSpeech.addVoice(voice);
    assertThat(shadowOf(textToSpeech).getVoices()).containsExactly(voice);
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech) Voice(android.speech.tts.Voice) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 3 with Voice

use of android.speech.tts.Voice in project Saiy-PS by brandall76.

the class SaiyTextToSpeech method getEngineDefaultSaiyVoice.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private SaiyVoice getEngineDefaultSaiyVoice() {
    final Voice voice = getDefaultVoice();
    if (voice != null) {
        final SaiyVoice saiyVoice = new SaiyVoice(voice);
        saiyVoice.setEngine(getInitialisedEngine());
        saiyVoice.setGender(saiyVoice.getName());
        if (DEBUG) {
            MyLog.i(CLS_NAME, "getEngineDefaultSaiyVoice: setting Gender: " + saiyVoice.getGender().name());
        }
        return saiyVoice;
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "getEngineDefaultSaiyVoice: voice null");
        }
        return null;
    }
}
Also used : Voice(android.speech.tts.Voice) SaiyVoice(ai.saiy.android.tts.helper.SaiyVoice) SaiyVoice(ai.saiy.android.tts.helper.SaiyVoice) TargetApi(android.annotation.TargetApi)

Example 4 with Voice

use of android.speech.tts.Voice in project Saiy-PS by brandall76.

the class SaiyTextToSpeech method getBoundSaiyVoice.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SaiyVoice getBoundSaiyVoice() {
    final Voice voice = getVoice();
    if (voice != null) {
        final SaiyVoice saiyVoice = new SaiyVoice(voice);
        saiyVoice.setEngine(getInitialisedEngine());
        saiyVoice.setGender(saiyVoice.getName());
        return saiyVoice;
    } else {
        return null;
    }
}
Also used : Voice(android.speech.tts.Voice) SaiyVoice(ai.saiy.android.tts.helper.SaiyVoice) SaiyVoice(ai.saiy.android.tts.helper.SaiyVoice) TargetApi(android.annotation.TargetApi)

Example 5 with Voice

use of android.speech.tts.Voice in project Saiy-PS by brandall76.

the class SaiyVoice method getSaiyVoices.

public static Set<SaiyVoice> getSaiyVoices(@NonNull final Set<Voice> voiceSet, @NonNull final String initialisedEngine) {
    final Set<SaiyVoice> saiyVoiceSet = new HashSet<>(voiceSet.size());
    if (initialisedEngine.matches(TTSDefaults.TTS_PKG_NAME_GOOGLE)) {
        final TTSDefaults.Google[] googleList = TTSDefaults.Google.values();
        SaiyVoice saiyVoice;
        String voicePattern;
        for (final Voice voice : voiceSet) {
            saiyVoice = new SaiyVoice(voice);
            saiyVoice.setEngine(initialisedEngine);
            voicePattern = Pattern.quote(voice.getName());
            for (final TTSDefaults.Google g : googleList) {
                if (g.getVoiceName().matches(voicePattern)) {
                    saiyVoice.setGender(g.getGender());
                    break;
                }
            }
            saiyVoiceSet.add(saiyVoice);
        }
    } else {
        SaiyVoice saiyVoice;
        for (final Voice voice : voiceSet) {
            saiyVoice = new SaiyVoice(voice);
            saiyVoice.setEngine(initialisedEngine);
            saiyVoice.setGender(Gender.getGenderFromVoiceName(voice.getName()));
            saiyVoiceSet.add(saiyVoice);
        }
    }
    return saiyVoiceSet;
}
Also used : Voice(android.speech.tts.Voice) HashSet(java.util.HashSet)

Aggregations

Voice (android.speech.tts.Voice)5 SaiyVoice (ai.saiy.android.tts.helper.SaiyVoice)2 TargetApi (android.annotation.TargetApi)2 TextToSpeech (android.speech.tts.TextToSpeech)2 Test (org.junit.Test)2 Config (org.robolectric.annotation.Config)2 HashSet (java.util.HashSet)1