How to use Text To Speech inside RecyclerView in Android

Fetching Comments ...

How to use Text To Speech inside RecyclerView in Android

What is TTS (Text To Speech)?

TSS or Text To Speech is library provided by Android, which is used to convert any word into voice. This means it can speak any word or phrase provided to this library.

So if you are creating Android Application which require some speaking words then you don’t need to record voice and play inside your application. You can simply pass your words to this library and it will do rest of the things.

We will use android.speech.tts.TextToSpeech library to convert our Strings into voice.

Overview to TTS

  • First step is to create instance of TextToSpeech.
  • Pass context to TextToSpeech’s contructor and Callback (which will be called when TextToSpeech will ready).
  • There is 3rd optional parameter which is “engine” which is used to pass custom TextToSpeech engine. (eg. Samsung TTS etc.).
  • After creating instance call speak() function from instance and it will speak the provided string.
  • You can also specify language of your text to TextToSpeech library.

Example Project:

TextToSpeech inside RecyclerView:

Code of MainActivity.kt
Code of activity_main.xml
Code of SpeechAdapter.kt
Code of adapter_item_speech.xml

Full Source Code

SpeechTextRecyclerView on Github

Star this github repository and Share with your friends as well.

LearnPainLess On Instagram

Get The Best Of All Hands Delivered To Your Inbox

Subscribe to our newsletter and stay updated.