@@ -0,0 +1,1457 @@
+package com.sunteam.ebook.util;%0A%0Aimport java.util.Locale;%0A%0Aimport android.content.Context;%0Aimport android.speech.tts.TextToSpeech;%0Aimport android.speech.tts.TextToSpeech.OnInitListener;%0A%0A/**%0A * TTS%E5%B7%A5%E5%85%B7%E7%B1%BB%E3%80%82%0A * %0A * @author wzp%0A */%0Apublic class TTSUtils implements OnInitListener%0A%7B%0A%09private static TTSUtils instance = null;%0A%09private TextToSpeech tts = null;%0A%09private boolean isSuccess = false;%0A%09%0A%09public static TTSUtils getInstance()%0A%09%7B%0A%09%09if( null == instance )%0A%09%09%7B%0A%09%09%09instance = new TTSUtils();%0A%09%09%7D%0A%09%09%0A%09%09return instance;%0A%09%7D%0A%09%0A%09//%E5%88%9D%E5%A7%8B%E5%8C%96%0A%09public void init( Context context )%0A%09%7B%0A%09%09tts = new TextToSpeech( context.getApplicationContext(), this );%0A%09%7D%0A%0A%09//%E6%98%AF%E5%90%A6%E5%88%9D%E5%A7%8B%E5%8C%96%E6%88%90%E5%8A%9F%0A%09public boolean isSuccess()%0A%09%7B%0A%09%09return%09isSuccess;%0A%09%7D%0A%09%0A%09@Override%0A%09public void onInit(int status) %0A%09%7B%0A%09%09// TODO Auto-generated method stub%0A%09%09if (status == TextToSpeech.SUCCESS)%0A%09%09%7B%0A%09%09%09int result = tts.setLanguage(Locale.CHINA);%0A%09%09%09if( result == TextToSpeech.LANG_MISSING_DATA %7C%7C result == TextToSpeech.LANG_NOT_SUPPORTED )%0A%09%09%09%7B%0A%09%09%09%09isSuccess = false;%0A%09%09%09%7D%0A%09%09%09else%0A%09%09%09%7B%0A%09%09%09%09isSuccess = true;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09%09%09isSuccess = false;%0A%09%09%7D%0A%09%7D%0A%09%0A%09//%E6%9C%97%E8%AF%BB%0A%09public void speak( final String content )%0A%09%7B%0A%09%09if( isSuccess && tts != null )%0A%09%09%7B%0A%09%09%09if( tts.isSpeaking() )%0A%09%09%09%7B%0A%09%09%09%09tts.stop();%0A%09%09%09%7D%09//%E5%A6%82%E6%9E%9C%E6%AD%A3%E5%9C%A8%E6%9C%97%E8%AF%BB%EF%BC%8C%E5%85%88%E5%81%9C%E6%AD%A2%0A%09%09%09%0A%09%09%09tts.speak(content, TextToSpeech.QUEUE_FLUSH, null );%0A%09%09%7D%0A%09%7D%0A%09%0A%09//%E5%81%9C%E6%AD%A2%E6%9C%97%E8%AF%BB%0A%09public void stop()%0A%09%7B%0A%09%09if( isSuccess && tts != null )%0A%09%09%7B%0A%09%09%09if( tts.isSpeaking() )%0A%09%09%09%7B%0A%09%09%09%09tts.stop();%0A%09%09%09%7D%09//%E5%A6%82%E6%9E%9C%E6%AD%A3%E5%9C%A8%E6%9C%97%E8%AF%BB%EF%BC%8C%E5%85%88%E5%81%9C%E6%AD%A2%0A%09%09%7D%0A%09%7D%0A%7D%0A

添加TTS工具类。