Spring 语音播报
作者使用工具网址提取网址:https://pan.baidu.com/s/1pNTkmuaUeKObcCtJg1mCTg
提取码:5ffn
步骤:
-
将jacob-1.18-M2-x64.dll 复制到 C:\Program Files\Java\jre1.8.0_271\bin 【该路径是你软件使用的JDK版本路径的bin目录】
-
将jacob-1.18-M2-x64.dll 复制到 C:\Windows\System32
-
在Spring项目的WEB-INF/bin 导入jacob.jar
-
编写一个测试方法
@Test
public void showJacob() {
this.JacobUtil("static");
}
public void JacobUtil(String arge) {
/*1. 创建音响对象*/
ActiveXComponent activeXComponent = new ActiveXComponent("Sapi.SpVoice");
/*2. 设置音量(0~100)*/
activeXComponent.setProperty("Volume", new Variant(100));
/*3. 设置朗读速度(-10~10)*/
activeXComponent.setProperty("Rate", new Variant(1));
/*4. 选取读取对象*/
Dispatch dispatch = activeXComponent.getObject();
/*5. 执行朗读*/
Dispatch.call(dispatch, "Speak", new Variant(arge));
/*6. 关闭对象和音响*/
dispatch.safeRelease();
activeXComponent.safeRelease();
}
注意,电脑如果是32位的操作一样,不过1、2不复制的文件名称为 :jacob-1.18-M2-x86.dll
如果在使用过程中遇到什么问题,感谢分享 ^_^ .