废话不多说,直接上菜。
首先,你确实要确保你的minSdkVersion 大于22或是21吧,这个才能支持这个标签<queries>,因为好像是21还是22才引入的这个标签。开始,在初始化的时候
mTextToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == SUCCESS) {
Log.e(TAG, "onInit: 初始化成功" );
} else {
Log.e(TAG, "onInit: 初始化失败");
}
}
});
TextToSpeech在Android 11之前,status返回的是0,也就是sucess中去,可以正常进行语音播报,你可以设置这些,并进行文字转语音播报。
mTextToSpeech.setLanguage(Locale.CHINA);
mTextToSpeech.setPitch(1.0f);//方法用来控制音调
mTextToSpeech.setSpeechRate(0.8f);//用来控制语速
mTextToSpeech.speak("测试语音", TextToSpeech.QUEUE_FLUSH, null, null);
但是在Android 11之后的版本中,你就会发现&