链接:https://pan.baidu.com/s/1BhXGCBSifLxCLDsZ-Q8Rpw
提取码:dgbg
64位操作系统,下载jocab,放入jdk安装目录bin目录下
Maven依赖:
<dependency> <groupId>com.hynnet</groupId> <artifactId>jacob</artifactId> <version>1.18</version> </dependency> 代码如下:
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComFailException;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import org.apache.log4j.Logger;
public class VoicePlaybackUtils {
private static Logger logger = Logger.getLogger(VoicePlaybackUtils.class);
/**
* 语音转文字并播放
*
* @param text 要播放的文字
* @throws Exception 异常捕捉
*/
public static void textToSpeech(String text) throws Exception {
ActiveXComponent ax = null;
try {
ax = new ActiveXComponent("Sapi.SpVoice");
/