1.需要的jar包:


2.把dll文件放在%JAVA_HOME%\bin下(注意系统是32位还是64位),也可以放在C:\Windows\System32下,如果是64位应该放在C:\Windows\SysWOW64



3.java代码
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class Test {
public static void main(String[] args) { ActiveXComponent sap = new
ActiveXComponent("Sapi.SpVoice"); // Dispatch是做什么的? Dispatch sapo =
sap.getObject(); try { // 音量 0-100 sap.setProperty("Volume", new Variant(100));
// 语音朗读速度 -10 到 +10 sap.setProperty("Rate", new Variant(-2)); Variant
defalutVoice = sap.getProperty("Voice"); Dispatch dispdefaultVoice =
defalutVoice.toDispatch(); Variant allVoices = Dispatch.call(sapo,
"GetVoices"); Dispatch dispVoices = allVoices.toDispatch(); Dispatch setvoice =
Dispatch.call(dispVoices, "Item", new Variant(1)).toDispatch();
ActiveXComponent voiceActivex = new ActiveXComponent(dispdefaultVoice);
ActiveXComponent setvoiceActivex = new ActiveXComponent(setvoice); Variant item
= Dispatch.call(setvoiceActivex, "GetDescription"); // 执行朗读 Dispatch.call(sapo,
"Speak", new Variant("太好玩了,啊哈哈哈!")); } catch (Exception e) {
e.printStackTrace(); } finally { sapo.safeRelease(); sap.safeRelease(); } }
}

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信