您的位置:首页 > 其它

TextToSpeech之阅读文字

2015-09-21 15:58 369 查看
创建阅读类

/**
* Created by RongGuang on 2014-11-21.
* 中文朗读
*/
public class ChineseToSpeech {
private TextToSpeech textToSpeech;

public ChineseToSpeech() {
this.textToSpeech = new TextToSpeech(Application.getContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = textToSpeech.setLanguage(Locale.CHINA);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
new CoolToast(Application.getContext()).show("不支持朗读功能");
}
}
}
});
}

public void speech(String text) {
textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}

public void destroy() {
if (textToSpeech != null) {
textToSpeech.stop();
textToSpeech.shutdown();
}
}
}


在使用的时候直接调用相应的方法即可实现阅读。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: