Java Code Examples for android.speech.tts.TextToSpeech#speak()

The following examples show how to use android.speech.tts.TextToSpeech#speak() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Accessibility.java    From OsmGo with MIT License 6 votes vote down vote up
@PluginMethod()
public void speak(PluginCall call) {
  final String value = call.getString("value");
  final String language = call.getString("language", "en");
  final Locale locale = Locale.forLanguageTag(language);

  if (locale == null) {
    call.error("Language was not a valid language tag.");
    return;
  }

  tts = new TextToSpeech(getContext(), new TextToSpeech.OnInitListener() {
    @Override
    public void onInit(int i) {
      tts.setLanguage(locale);
      tts.speak(value, TextToSpeech.QUEUE_FLUSH, null, "capacitoraccessibility" + System.currentTimeMillis());
    }
  });

  // Not yet implemented
  throw new UnsupportedOperationException();
}
 
Example 2
Source File: TtsSpeaker.java    From sample-tensorflow-imageclassifier with Apache License 2.0 5 votes vote down vote up
public void speakResults(TextToSpeech tts, Collection<Recognition> results) {
    if (results.isEmpty()) {
        tts.speak("I don't understand what I see.", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
        if (isFeelingFunnyNow()) {
            tts.speak("Please don't unplug me, I'll do better next time.",
                    TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
        }
    } else {
        if (isFeelingFunnyNow()) {
            playJoke(tts);
        }
        Iterator<Recognition> it = results.iterator();

        Recognition first = it.hasNext() ? it.next() : null;
        Recognition second = it.hasNext() ? it.next() : null;
        if (results.size() == 1
                || first.getConfidence() > SINGLE_ANSWER_CONFIDENCE_THRESHOLD) {
            tts.speak(String.format(Locale.getDefault(),
                    "I see a %s", first.getTitle()),
                    TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
        } else {
            tts.speak(String.format(Locale.getDefault(), "This is a %s, or maybe a %s",
                    first.getTitle(), second.getTitle()),
                    TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
        }
    }

}
 
Example 3
Source File: TtsSpeaker.java    From sample-tensorflow-imageclassifier with Apache License 2.0 5 votes vote down vote up
@Override
public void speak(TextToSpeech tts) {
    tts.setPitch(0.2f);
    tts.speak("I see dead people...", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
    tts.setPitch(1);
    tts.speak("Just kidding...", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
}
 
Example 4
Source File: TtsSpeaker.java    From sample-tensorflow-imageclassifier with Apache License 2.0 5 votes vote down vote up
@Override
public void speak(TextToSpeech tts) {
    tts.setPitch(1.8f);
    tts.setSpeechRate(1.4f);
    tts.speak("It's a bird! It's a plane! It's superman", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
    tts.setPitch(1);
    tts.setSpeechRate(1f);
    tts.speak("Just kidding...", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
}
 
Example 5
Source File: TtsSpeaker.java    From sample-tensorflow-imageclassifier with Apache License 2.0 5 votes vote down vote up
@Override
public void speak(TextToSpeech tts) {
    tts.setPitch(1.3f);
    tts.setSpeechRate(1.6f);
    tts.speak("Hey, that looks like me!", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
    tts.setPitch(1);
    tts.setSpeechRate(1f);
    tts.speak("Just kidding...", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
}
 
Example 6
Source File: TtsSpeaker.java    From sample-tensorflow-imageclassifier with Apache License 2.0 5 votes vote down vote up
@Override
public void speak(TextToSpeech tts) {
    tts.setPitch(0.7f);
    tts.setSpeechRate(1.6f);
    tts.speak("Oops, someone left the lens cap on!", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
    tts.setPitch(1);
    tts.setSpeechRate(1f);
    tts.speak("Just kidding...", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
}
 
Example 7
Source File: TtsHelper.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
public static void speak(Context context, String text) {
    Log.i(TtsHelper.class.getName(), "speak");

    Log.i(TtsHelper.class.getName(), "text: " + text);

    LiteracyApplication literacyApplication = (LiteracyApplication) context;
    TextToSpeech tts = literacyApplication.getTts();
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, null);
}
 
Example 8
Source File: TtsHelper.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
public static void speak(Context context, String text) {
    Log.i(TtsHelper.class.getName(), "speak");

    Log.i(TtsHelper.class.getName(), "text: " + text);

    LiteracyApplication literacyApplication = (LiteracyApplication) context;
    TextToSpeech tts = literacyApplication.getTts();
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, null);
}
 
Example 9
Source File: SpokenTextMoment.java    From android-play-games-in-motion with Apache License 2.0 5 votes vote down vote up
/**
 * Use TextToSpeech to say the words associated with this Moment.
 */
private void speak() {
    TextToSpeech textToSpeech = getMission().getService().getTextToSpeech();
    textToSpeech.setOnUtteranceProgressListener(mUtteranceProgressListener);
    textToSpeech.playSilence(SILENCE_LENGTH_MILLIS, TextToSpeech.QUEUE_ADD, null);
    HashMap<String, String> map = new HashMap<>();
    map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, mData.getMomentId());
    textToSpeech.speak(mData.getTextToSpeak(), TextToSpeech.QUEUE_ADD, map);
}
 
Example 10
Source File: TtsSpeaker.java    From sample-tensorflow-imageclassifier with Apache License 2.0 4 votes vote down vote up
public void speakReady(TextToSpeech tts) {
    tts.speak("I'm ready!", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
}
 
Example 11
Source File: TtsSpeaker.java    From sample-tensorflow-imageclassifier with Apache License 2.0 4 votes vote down vote up
@Override
public void speak(TextToSpeech tts) {
    tts.speak(mMessage, TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
}
 
Example 12
Source File: TTS.java    From always-on-amoled with GNU General Public License v3.0 4 votes vote down vote up
public void sayCurrentStatus() {
    tts = new TextToSpeech(context, TTS.this);
    tts.setLanguage(Locale.getDefault());
    tts.speak("", TextToSpeech.QUEUE_FLUSH, null);
}