意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

java文字转声音播报hynnet

来源:恒创科技 编辑:恒创科技编辑部
2024-01-27 19:44:59


介绍

需要 dll 这玩意,拷贝到位置

* jacob-1.18-x64.dll 放到C:\Windows\System32


java文字转声音播报hynnet

jacob-1.18-x86.dll 放到C:\Windows\SysWOW64

pom依赖
<dependency>
<groupId>com.hynnet</groupId>
<artifactId>jacob</artifactId>
<version>1.18</version> <!-- 注:如提示报错,先升级基础包版,无法解决可联系技术支持 -->
</dependency>

代码依赖
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

代码
package com.superman.test;

import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

/**
*
* @author yushen
*
*/
public class testSY {
private final static Log log = LogFactory.getLog(testSY.class);
/**
*
* <dependency>
<groupId>com.hynnet</groupId>
<artifactId>jacob</artifactId>
<version>1.18</version> <!-- 注:如提示报错,先升级基础包版,无法解决可联系技术支持 -->
</dependency>
* jacob-1.18-x64.dll 放到C:\Windows\System32

jacob-1.18-x86.dll 放到C:\Windows\SysWOW64
* @param args
*/

static String bf = "北山帝皇,娃哈哈,小老弟,来玩啊!";

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(bf));

System.out.println("声音播放成功!");
} catch (Exception e) {
e.printStackTrace();
log.error(e.toString());

} finally {
sapo.safeRelease();
sap.safeRelease();
}
}

}

* jacob-1.18-x64.dll


ok

持续更新


上一篇: 命令行中使用字典 下一篇: 手机怎么远程登录云服务器?