微软自带TTS(Text To Speech) 语音引擎,可以将文本转换成语音播报。
现在通过Java程序,利用Windows自带的TTS实现语言的播报。
需要jar包
下载jacob.jar
将jar包添加到项目
java代码
package com.wanmait.test;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class TestMain {
public static void main(String[] args) {
// TODO Auto-generated method stub
ActiveXComponent com = new ActiveXComponent("Sapi.SpVoice");
//调用WindowsAPI的com组件 Sapi.SpVoice是Windowscom组件的名称
Dispatch dis = com.getObject();
//从com组件中间获得调度目标
try {
com.setProperty("Volume", new Variant(100));
//设置语言组件的音量0~100
com.setProperty("Rate", new Variant(-1));
//设置语音组件的朗读速率 -10~10
Dispatch.call(dis, "Speak", new Variant("万码"));
//调用speek方法 开始朗读
} catch (Exception e) {
e.printStackTrace();
} finally {
dis.safeRelease();
com.safeRelease();
}
}
}

0条评论
点击登录参与评论