java文本转语音
下载jar包https://github.com/freemansoft/jacob-project/releases
解压,将jacob-1.18-xxx.dll相应放到项目使用的JAVA_HOMEbin下
java代码
public class Test {
public static ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");
public static Dispatch sapo=sap.getObject();
public static void main(String[] args) {
String str ="测试声音是否正常";
readText(str);
}
public static void readText(String queue) {
try {
//声音大小
sap.setProperty("Volume", new Variant(100));
//语速
sap.setProperty("Rate",new Variant(-2));
//发声
Dispatch.call(sapo,"Speak",new Variant(queue));
} catch (Exception e) {
e.printStackTrace();
}finally{
if(sap==null){
sap = new ActiveXComponent("Sapi.SpVoice");
}
if(sapo==null){
sapo = sap.getObject();
}
}
}
}