The Android system supports speech synthesis in five languages (German, English, Spanish, French, and Italian), excluding Chinese. However, the Android system allows third parties to support TTS in Chinese, therefore, we only need to install a suitable third-party TTS application and set it in the system.
There are also several TTS tools available. In fact, we don't have to worry about which one to choose. At present, we 'd better use "xunfei voice +". The speech is fluent and the language speed is optional, the software is still being updated. For some Android 4.0 systems that may not be able to check the TTS option of xunfei, you only need to install the latest version of xunfei voice +.
Then, you only need to call the TextToSpeech class provided by the system and implement the corresponding interface.
Here is a simple speech synthesis control class. If you create an object, you can directly synthesize and play the text.
The Code is as follows:
package cn.com.bfyb;import java.util.Locale;import android.content.Context;import android.speech.tts.TextToSpeech;import android.widget.Toast;public class TextSpeaker {private Context context;private TextToSpeech tts;public TextSpeaker(final Context context) {// TODO Auto-generated constructor stubthis.context = context;tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {@Overridepublic void onInit(int status) {// TODO Auto-generated method stubif (status == TextToSpeech.SUCCESS){int result = tts.setLanguage(Locale.CHINA);if (result == TextToSpeech.LANG_MISSING_DATA|| result == TextToSpeech.LANG_NOT_SUPPORTED){Toast.makeText(context, "Language is not available.",Toast.LENGTH_SHORT).show();}}}});}public void speak(String text) {tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);}}
Code: http://pan.baidu.com/s/1gdtErQF
Tencent voice + official website download: http://open.voicecloud.cn/speechservice