How to speak all the items in a list in android studio

Viewed 56

I have a list in which there are some strings.

I want to convert all the strings to speech and have them spoken in Android Studio.

Suppose there is a list:

[apple, banana, orange, mango, ....]

I want to have all the items in the above list spoken.

So the app will speak: "apple", "banana", "orange", "mango"

I want to use TextToSpeech library in android to have the items on the list spoken.

Is there any way so that we can do so?

1 Answers

Look at this tutorial how to implement TextToSpeech:

https://code.tutsplus.com/tutorials/android-sdk-using-the-text-to-speech-engine--mobile-8540

Here are all supported Locales in Java8, if you want to use a Locale, which isn´t predefined by a constant in Locale (you have to use the Language Tag and create a new Locale):

https://www.oracle.com/java/technologies/javase/jdk8-jre8-suported-locales.html

After following all steps of the tutorial you can implement the speakWords() method and use it for speaking the Strings from your List.

  private void speakWords(String speech) {
 
            //speak straight away
            myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
    }

Can afterwards be used with:

speakWords(NameOfYourList.get(int index));

speakWords() can e.g. be triggered by a Buttonclick (click event).
After Button click index++ and next word of the List will be chosen.

Related