# Is there a text to speech for Android?

**URL:** <https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777>\
**Category:** Processing for Android\
**Created:** [January 4, 2021, 10:21pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777 "2021-01-04T22:21:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [January 4, 2021, 10:21pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/1 "2021-01-04T22:21:03Z")

</div>

is there a text to speech for Android?

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [January 4, 2021, 11:07pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/2 "2021-01-04T23:07:39Z")

</div>

Hi,

You can check those previous threads :

> [@Speech recognition for android mode](https://discourse.processing.org/t/speech-recognition-for-android-mode/463):
>
> Hello, Does someone know a speech recognition (speech to text) library for Android Mode in processing? Thanks

> [@How to add speech to text in processing android](https://discourse.processing.org/t/how-to-add-speech-to-text-in-processing-android/22128):
>
> How can I implement speech to text mechanism in processing android?

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [January 6, 2021, 5:59pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/3 "2021-01-06T17:59:29Z")

</div>

I dont Unserstand it

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [January 11, 2021, 8:35pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/4 "2021-01-11T20:35:09Z")

</div>

@noel can you Help me? 😕

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 11, 2021, 9:45pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/5 "2021-01-11T21:45:58Z")

</div>

What is it that you don’t understand? The code from akenaton given in the link above is also on my repo [here](https://github.com/EmmanuelPil/Android-java-code-utilities-widgets-for-Processing-for-Android/blob/master/Speech%20recognition), and it works perfectly.

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [January 11, 2021, 11:14pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/6 "2021-01-11T23:14:30Z")

</div>

I hiss that my cell phone can talk to me

I need TTS

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 12, 2021, 9:49am UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/7 "2021-01-12T09:49:52Z")

</div>

> [@Rogo](#):
>
> 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](https://stackoverflow.com/questions) for example.

```auto
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();
}

```

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [January 12, 2021, 4:29pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/8 "2021-01-12T16:29:39Z")

</div>

Okay now i try it

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

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 12, 2021, 4:40pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/9 "2021-01-12T16:40:56Z")

</div>

> [@Rogo](#):
>
> can i Change the language to german?

> [@noel](#):
>
> 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](https://stackoverflow.com/questions) for example.

?..

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 12, 2021, 4:43pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/10 "2021-01-12T16:43:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [January 12, 2021, 6:11pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/11 "2021-01-12T18:11:04Z")

</div>

```auto
my_tts.setLanguage(Locale.DE);

```

Is not working

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 12, 2021, 6:12pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/12 "2021-01-12T18:12:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [January 12, 2021, 6:13pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/13 "2021-01-12T18:13:13Z")

</div>

My Phone is in German

Yes it’s installed

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 12, 2021, 6:23pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/14 "2021-01-12T18:23:58Z")

</div>

Try

```auto
my_tts.setLanguage(Locale.GERMANY);

```

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 12, 2021, 6:25pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/15 "2021-01-12T18:25:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 12, 2021, 7:06pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/16 "2021-01-12T19:06:37Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 12, 2021, 7:08pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/17 "2021-01-12T19:08:41Z")

</div>

@noel ==== you are probably right

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [January 12, 2021, 7:25pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/18 "2021-01-12T19:25:53Z")

</div>

Thank you so much ❤

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [January 12, 2021, 7:36pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/19 "2021-01-12T19:36:27Z")

</div>

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

for example:

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

```

And much more…?

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 12, 2021, 7:40pm UTC](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777/20 "2021-01-12T19:40:25Z")

</div>

> [@Rogo](#):
>
> can you do it now also do that I can talk to the cell phone?

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

[Next page](https://discourse.processing.org/t/is-there-a-text-to-speech-for-android/26777.md?page=2)
