文章主要讲的是以前做项目时实现的来短信或来电话时语音播报的功能实现,记录下来做个总结。 1.实现语音播报的关键 -- 语音播报工具类(TtsUtil.java) 为了方便
文章主要讲的是以前做项目时实现的来短信或来电话时语音播报的功能实现,记录下来做个总结,,其中有些数据库的值是自己在其他地方加的开关。
1.实现语音播报的关键 -- 语音播报工具类(TtsUtil.java)
package com.android.mms.transaction;
import android.content.Context;
import android.provider.Settings;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.util.Log;
public class TtsUtil {
public static TextToSpeech mTts;
public static void read(Context ctx, final String content) {
Log.d("dwj",
"messageRead = "
+ Settings.Secure.getInt(ctx.getContentResolver(),
"hands_free_mode", 0));
if (Settings.Secure.getInt(ctx.getContentResolver(), "hands_free_mode",
0) == 0) {
return;
}
if (null != mTts) {
mTts.stop();
try {
mTts.shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
mTts = new TextToSpeech(ctx, new OnInitListener() {
@Override
public void onInit(int status) {