The TextToSpeech API has been part of Android since the early days, but there was a significant change in API 21, Android 5 Lollipop. I’ll describe how to make an Android device speak out loud with a project that has its minimum SDK set to level 21. The TextToSpeech classes and interfaces are in the package android.speech.tts.
- [Voiceover] The text-to-speech API…has been part of Android since the early days.…But there was a significant change in API 21.…Android 5.0 Lollipop.…I'll describe how to make an Android device…speak out loud with a project…that has its minimum SDK set to API level 21.…This project is named TextToSpeech.…In the app's current state,…you can type a value into an edit text control…and then press the Run Code button.…
And you'll simply repeat whatever text…that you've typed in.…Right now you're just seeing the text,…but after the changes I'm about to make,…you'll be able to hear the text as well.…So I'll start in the MainActivity class.…And I'll declare two private fields.…The first one will be an instance of the class TextToSpeech.…This is a member of the package android.speech.tts.…And I'll name it simply tts.…
The next one will be a boolean value,…and I'll name that ttsInitialized.…Next, I'll instantiate the text-to-speech object…in the onCreate method.…This is a simple bit of code.…I'll say tts = new TextToSpeech…
Watch these Java tutorials to learn smarter, more efficient methods for Android app development.
- Preparing the development environment
- Packaging and running Android apps
- Optimizing Java code for Android
- Implementing event handler interfaces
- Defining custom callback methods
- Working with the Android SDK's Java packages
- Storing data
- Reading text files
- Parsing JSON and XML data
- Managing device sensors
- Playing audio