参考: https://blog.csdn.net/shendan00/article/details/43525437#commentBox

https://www.jianshu.com/p/0cf01f089660

https://developer.android.google.cn/reerence/android/speech/tts/TextToSpeech

 

public class MyTTS extends UtteranceProgressListener implements TextToSpeech.OnInitListener {    private static final String TAG = MyTTS.class.getSimpleName();    private static MyTTS mInstance;    public static MyTTS getInstance() {        if (mInstance == null) {            synchronized (MyTTS.class) {                if (mInstance == null) {                    mInstance = new MyTTS();                }            }        }        return mInstance;    }    private MyTTS() {        super();    }    private TextToSpeech mTextToSpeech;    public void init(Context context) {        mTextToSpeech = new TextToSpeech(context, this);        mTextToSpeech.setOnUtteranceProgressListener(this);    }    public void speak(String text) {        if (mTextToSpeech != null)            mTextToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null, TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID);    }    public void release() {        if (mTextToSpeech != null) {            mTextToSpeech.shutdown();        }    }    @Override    public void onInit(int status) {        if (status == TextToSpeech.SUCCESS && mTextToSpeech != null) {            int result = mTextToSpeech.setLanguage(Locale.ENGLISH);            if (result == TextToSpeech.LANG_MISSING_DATA                    || result == TextToSpeech.LANG_NOT_SUPPORTED                    || result == TextToSpeech.ERROR) {                Log.d(TAG, "onInit 数据丢失或语言不支持");            }            if (result == TextToSpeech.LANG_AVAILABLE) {                Log.d(TAG, "onInit 支持该语言");            }            Log.d(TAG, "onInit ok");        }    }    @Override    public void onStart(String utteranceId) {        Log.d(TAG, "onStart " + utteranceId);    }    @Override    public void onDone(String utteranceId) {        Log.d(TAG, "onDone " + utteranceId);    }    @Override    public void onError(String utteranceId) {        Log.d(TAG, "onError " + utteranceId);    }}

 

 

更多相关文章

  1. build WebRTC for android
  2. android build (可参考之建立android编译环境)
  3. Android自动化测试之MonkeyRunner之MonkeyRunner(九)
  4. Android(安卓)支持多屏幕机制
  5. [Android] 问题记录 - Android(安卓)支持的度量单位
  6. Android(安卓)NDK带来什么
  7. TextView实现电话、网址链接
  8. android studio 使用cmake支持C++出现无法sync cmake error的问
  9. Android(安卓)的大牛的博客 提供给大家参考

随机推荐

  1. 使用css中子div的基线对齐div
  2. HTML5<meta name="viewport"/>标签常见属
  3. 将HTML转换为图片传到服务器
  4. 网站开发进阶(二十五)js如何将html表格导
  5. 隐藏嵌套div的滚动条,但仍然可以滚动[重复
  6. 自动设置绝对子级的父div的高度
  7. JS和JQuery中如何获取和修改控件显示内容
  8. 【WEB基础】HTML & CSS 基础入门(3)段落及
  9. JQuery查找并更改字符串的样式
  10. 使用BeautifulSoup解析HTML时遇到问题