Android's auto-read support is done primarily through Texttospeech, which provides the following constructor
Texttospeech (Context Context,texttospeech.oninitlistener Listener)
When you create a Texttospeech object, you must first provide a Oninitlistener listener-the listener is responsible for listening to the Texttospeech initialization results.
The two most common methods of Texttospeech are as follows:
1, Speak (String text,int queuemode,hashmap<string,string> params)
2, Synthesizetofile (String text,hashmap<string,string> params,string filename)
The above two methods are used to convert text content to audio, except that the Speak method is to play the converted audio, while the synthesizetofile is to save the converted audio as a sound file.
The params in the above two methods are used to specify the parameters for the sound conversion, and the Queuemode parameter in the Speak () method specifies the TTS pronunciation queue mode, which supports the following two constants.
1, Texttospeech.queue_flush: If you specify this mode, when TTS calls the Speak method, it interrupts the task that the current instance is running (or it can be understood to clear the current voice task and instead perform a new voice task)
2, Texttospeech.queue_add: If specified as the mode, when the TTS calls the Speak method, the new pronunciation task will be added to the current Pronunciation task queue-that is, after the completion of the task queues of the pronunciation task is completed in the execution of the Speak () method specifies the pronunciation task.
When the program has run out of Texttospeech objects, you can call its shutdown () in the activity's OnDestroy () method to close the Texttospeech and release the resources it occupies.
The steps for using Texttospeech are as follows:
1, create the Texttospeech object, when it was created, the incoming Oninitlistener listener listens for the creation success.
2. Set the language, country option for Texttospeech, and determine whether TTS supports the language or country option by the return value.
3. Call the Speak () or Synthesizetofile method.
4, close TTS, recycling resources.
Auto-read aloud (TTS) in Android