java字符串输入然后语音输出
1.将jacob.jar考到项目中进行构建路径。
2.将jacob-1.17-M2-x32.dll或者jacob-1.17-M2-x64.dll,考到系统盘:\Windows\System32\下面。
3.将jacob-1.17-M2-x32.dll或者jacob-1.17-M2-x64.dll,考到JDK安装目录的bin下面。
public static void main(String[] args) throws IOException {
ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");
Dispatch sapo = sap.getObject();
try {
// 音量 0-100
sap.setProperty("Volume", new Variant(100));
// 语音朗读速度 -10 到 +10
sap.setProperty("Rate", new Variant(2));
// 执行朗读
Dispatch.call(sapo, "Speak", new Variant("I am work"));
} catch (Exception e) {
e.printStackTrace();
} finally {
sapo.safeRelease();
sap.safeRelease();
}
}

浙公网安备 33010602011771号