SpeechUtility.createUtility(context, APPID);
player = SpeechSynthesizer.createSynthesizer(context, mTtsInitListener);
player.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_LOCAL);
//设置发音人资源路径
player.setParameter(ResourceUtil.TTS_RES_PATH,getResourcePath());
//设置发音人
player.setParameter(SpeechConstant.VOICE_NAME,"xiaoyan");
//获取发音人资源路径
private static StringgetResourcePath(){
StringBuffer tempBuffer =new StringBuffer();
String type="xtts";
//合成通用资源
tempBuffer.append(ResourceUtil.generateResourcePath(context, ResourceUtil.RESOURCE_TYPE.assets, type+"/common.jet"));
tempBuffer.append(";");
//发音人资源
tempBuffer.append(ResourceUtil.generateResourcePath(context, ResourceUtil.RESOURCE_TYPE.assets, type+"/xiaoyan.jet"));
return tempBuffer.toString();
}
必须设置params才会使用离线版,否则默认为在线版
需要在assets中新建xtts文件夹,对应type=“xtts”
在xtts中放入common.jet和对应的语音jet
在getResourcePath中设置对应的语音jet
文档中没写,demo中才有这段代码,做个记录