Auto-read aloud (TTS) in Android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.