1.下载科大讯飞语音引擎安装到手机上,在设置->语言->高级->文字转语音
? ?把首选引擎由Pico TTS改为科大讯飞语音引擎
2.代码中使用
private TextToSpeech textToSpeech;
textToSpeech = new TextToSpeech(this, status -> {
if (status == textToSpeech.SUCCESS) {
int result = textToSpeech.setLanguage(Locale.CHINESE);
if (result != TextToSpeech.LANG_COUNTRY_AVAILABLE && result != TextToSpeech.LANG_AVAILABLE){
Toast.makeText(this, "TTS暂时不支持这种语音", Toast.LENGTH_SHORT).show();
}
}
});
// 设置音调,值越大声音越尖(女生),值越小则变成男声,1.0是常规
textToSpeech.setPitch(1.0f);
// 设置语速
textToSpeech.setSpeechRate(1.0f);
textToSpeech.stop(); // 不管是否正在朗读TTS都被中断
textToSpeech.shutdown(); // 关闭,释放资源(这是完全释放textToSpeech,在完全不需要的时候再调用)
|