Now in the development of Android Chinese voice broadcast has a variety of cloud services, SDKs, APIs and so on, but most of the services are required to support the Internet for speech synthesis, in Chinese speech synthesis, Iflytek is undoubtedly the leader, And it also provides downloads for offline speech synthesis packages that need to be paid by distribution and usage time.
The Android native API itself also provides TTS functionality, and we can use the Texttospeech class to broadcast the words you want to pronounce using a few lines of code, as follows:
1, first need to instantiate the Texttospeech class, in the Texttospeech constructor, you need to provide a Oninitlistener object to complete the initialization of the Texttospeech object settings, The OnInit method needs to be implemented in the Oninitlistener object, and we can call the SetLanguage method within the method
To set the language type, Local.china is Chinese, after setting up to determine whether the current system supports the language to be pronounced, the code is as follows:
@Override public void onInit (int status) { if (Status == Texttospeech.success) { result = Texttospeech.setlanguage (Locale.china); if (Result = = Texttospeech.lang_missing_data | | result == texttospeech.lang_not_supported) {Toast.maketext ( this , " lang_missing_data or lang_not_supported ! "
2, then need to pronounce the place call Texttospeech instance Object Speak method can complete the voice broadcast, before the broadcast can be called SetPitch method to set the tone, the default value is 1, the higher the value of the higher the tone, the code is as follows:
// The tone Texttospeech.speak can also be modified in the system setup ("Hello, let's Test the voice function!", texttospeech.queue_flush, NULL);
3, using Texttospeech for voice broadcast use of the language data on the device Android system set up the TTS voice packet, the default is not supported in Chinese, in my test plate for example, the default TTS package is Pico TTS, only support English, French, German, In several languages, such as Italian and Spanish,:
4, the Android system supports the custom third-party TTS Voice Library, we can download and install a "voice of Speech +", and in the system voice settings will be the TTS switch selected as "Voice fly Speech +",:
After that, we will be able to successfully TTS broadcast Chinese!
---done---
Android Chinese TTS