河南省住房城乡与建设厅网站首页,京东网站建设吗,宣传册设计与制作费用,溧阳网站优化1#xff0c;TextToSpeech类是android自带的#xff0c;但是部分设备需要支持TTS需要增加语音库#xff0c;我使用的是讯飞语音#xff08;离线的哦#xff09;。请自行下载并安装讯飞语音APK#xff0c;然后到系统设置中设置TTS功能默认使用该选项。有自带TTS库的可以省…1TextToSpeech类是android自带的但是部分设备需要支持TTS需要增加语音库我使用的是讯飞语音离线的哦。请自行下载并安装讯飞语音APK然后到系统设置中设置TTS功能默认使用该选项。有自带TTS库的可以省略该步骤。 2定义TTS对象
private TextToSpeech mTextToSpeechnull;
3调用每次调用都需要初始化 try{final String strSpeekNow strSpeek;mTextToSpeechnew TextToSpeech(this, new TextToSpeech.OnInitListener() {Overridepublic void onInit(int status) {if (statusTextToSpeech.SUCCESS) {//设置朗读语言int supportedmTextToSpeech.setLanguage(Locale.CHINESE);if ((supported!TextToSpeech.LANG_AVAILABLE)(supported!TextToSpeech.LANG_COUNTRY_AVAILABLE)) {CardManager.toast(VerificationResultActivity.this, 不支持当前语言);}}//设置音调,值越大声音越尖女生值越小则变成男声,1.0是常规mTextToSpeech.setPitch(1.0f);//设置语速mTextToSpeech.setSpeechRate(1.3f);mTextToSpeech.speak(strSpeekNow, TextToSpeech.QUEUE_FLUSH, null, null);}});} catch (Exception e) {//语音播报出错Log.e(tts,e.toString());}
4在onDestroy中关闭TTS if (mTextToSpeech!null) {mTextToSpeech.shutdown();//关闭TTS}