TextToSpeech mTts; mTts=newTextToSpeech(this, newTextToSpeech.OnInitListener() { @Override publicvoidonInit(int status) { // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR. if (status == TextToSpeech.SUCCESS) { // Set preferred language to US english. // Note that a language may not be available, and the result will indicate this. intresult= mTts.setLanguage(Locale.CHINA); // Try this someday for some interesting results. // int result mTts.setLanguage(Locale.FRANCE); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { // Lanuage data is missing or the language is not supported. Log.e(TAG, "Language is not available."); IntentinstallIntent=newIntent(); installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installIntent); } else { // Check the documentation for other possible result codes. // For example, the language may be available for the locale, // but not for the specified country and variant. // The TTS engine has been successfully initialized. // Allow the user to press the button for the app to speak again. Log.i(TAG,"初始化成功"); mTts.speak("初始化成功",TextToSpeech.QUEUE_FLUSH,null); } } else { // Initialization failed. Log.e(TAG, "Could not initialize TextToSpeech."); } } });