Is there a text to speech for Android?

is there a text to speech for Android?

Hi,

You can check those previous threads :

I dont Unserstand it

@noel can you Help me? :confused:

What is it that you don’t understand? The code from akenaton given in the link above is also on my repo here, and it works perfectly.

I hiss that my cell phone can talk to me

I need TTS

Oh… I am sorry, I got confused by the previous answers.
Try this code. You can also change the speed of the text being spoken, and the language. But before asking this here, I would like you to solve this yourself by searching here for example.

import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import java.util.Locale;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.speech.RecognizerIntent;
import android.content.*; 

String  str = "Hi there. This is your beloved phone speaking to you.";

TextToSpeech my_tts;
Activity activity;
Context context;

void setup() {
  fullScreen();
  background(0, 0, 200);
  fill(200);
  rect(width/4, 7*height/16, width/2, height/8);
  textAlign(CENTER, CENTER);
  textSize(60);
  fill(0);
  text("SPEAK", width/2, height/2);
  activity = this.getActivity();
  context = activity.getApplicationContext();
}

void draw(){}

void mousePressed() {
  if (mouseX < 3*width/4 && mouseX > width/4 &&
    mouseY > 7*height/16 && mouseY < 9*height/16) {
    try {
      my_tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
        @Override
          public void onInit(int status) {
          if (status == TextToSpeech.SUCCESS) {
            my_tts.setLanguage(Locale.UK);
            my_tts.speak(str, TextToSpeech.QUEUE_FLUSH, null);
          }
        }
      }
      );
    } 
    catch(Exception e) {
      println(e);
    }
  }
}

public void onPause() {
  if (my_tts !=null) {
    my_tts.stop();
    my_tts.shutdown();
  }
  super.onPause();
}
2 Likes

Okay now i try it

Edit: its Work can i Change the language to german?

?..

@Rogo === sure you can change the language; look inside the code where it is set.

my_tts.setLanguage(Locale.DE);

Is not working

@Rogo ===
is this language installed on the phone?

My Phone is in German

Yes it’s installed

Try

my_tts.setLanguage(Locale.GERMANY);

@Rogo === ok
what happens if you add: boolean al=mTts.isLanguageAvailable(Locale.DE)
println(al);

1 Like

So my phone is in Portuguese and I couldn’t set it either in this language this way.
My solution was to add these two lines:

final Locale myLocale = new Locale("pt", "BR"); 
my_tts.setLanguage(myLocale); 
my_tts.speak(str, TextToSpeech.QUEUE_FLUSH, null);

So I guess changing Locale(“pt”, “BR”);
to Locale(“de”, “DE”); could work

@noel ==== you are probably right

Thank you so much :heart:

can you do it now also do that I can talk to the cell phone?

for example:

If(talk=hello){
  my_tts.speak(Hello, TextToSpeech.QUEUE_FLUSH, null);
 }

And much more…?

Of course you can. I just don’t know if it will respond.
Or maybe you want to look at the first answer?