java文字转声音播报hynnet
需要 dll 这玩意,拷贝到位置
* jacob-1.18-x64.dll 放到C:\Windows\System32
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
持续更新
版权声明
本文仅代表作者观点,不代表博信信息网立场。