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.
- 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.
TextToSpeech inside RecyclerView:
Code of MainActivity.kt
Code of activity_main.xml
Code of SpeechAdapter.kt
Code of adapter_item_speech.xml
SpeechTextRecyclerView on Github
Star this github repository and Share with your friends as well.
Subscribe to our newsletter!
We'll send you the best of our blog just once a month. We promise.