将下载的jacob_1.9.zip包解压,将jacob.dll文件放到C:\Windows\System32和%JAVA_HOME%\bin路径下。
将jacob.jar导入到项目中
实现代码
public static void commonBroadcast(String content) {
ActiveXComponent activeXComponent = new ActiveXComponent("Sapi.SpVoice");
Dispatch dis = activeXComponent.getObject();
try {
//音量大小0-100
activeXComponent.setProperty("Volume", new Variant(100));
//语数-10 - 10
activeXComponent.setProperty("Rate", new Variant(0));
Dispatch.call(dis, "Speak", new Variant(content));
} catch (Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
} finally {
logger.info("释放功放资源");
dis.safeRelease();
activeXComponent.safeRelease();
}
}