简体   繁体   中英

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

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?

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 eg be triggered by a Buttonclick (click event).
After Button click index++ and next word of the List will be chosen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM