想自己做网站,专业模板网站制作价格,化工seo顾问,班级优化大师在做项目的过程中#xff0c;我们往往会用到语音播报——把文字转换成语音播放出来#xff0c;自动识别语言进行播报#xff0c;那么我们现在来看看怎么操作#xff1a;
1.下载jacob.jar#xff0c;下载地址#xff1a;这里
2.32位操作系统下载#xff1a;jacob-…在做项目的过程中我们往往会用到语音播报——把文字转换成语音播放出来自动识别语言进行播报那么我们现在来看看怎么操作
1.下载jacob.jar下载地址这里
2.32位操作系统下载jacob-1.17-M2-x32.dll64位操作系统下载jacob-1.17-M2-x64.dll下载地址这里
3.将jacob.jar考到项目中进行构建路径。
4.将jacob-1.17-M2-x32.dll或者jacob-1.17-M2-x64.dll考到系统盘:\Windows\System32\下面。
5.将jacob-1.17-M2-x32.dll或者jacob-1.17-M2-x64.dll考到JDK安装目录的bin下面。
然后写个test方法测试一下即可测试代码如下 /**
* Title: Voice.java
* Package org.util
* Description: TODO该方法的主要作用
* author A18ccms A18ccms_gmail_com
* date 2017-7-3 下午9:03:45
* version V1.0
*/
package cn.bdqn.bdqn.utils;import org.junit.Test;import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;/** * * 项目名称avoice * 类名称Voice * 类描述 语音播报工具类* 创建人Mu Xiongxiong * 创建时间2017-7-3 下午9:03:45 * 修改人Mu Xiongxiong * 修改时间2017-7-3 下午9:03:45 * 修改备注 * version * */
public class Voice {/*** * Title: strat* Description: 该方法的主要作用朗读* param param content* param param type 设定文件 0:开始1停止* return 返回类型void * throws*/public void strat(String content, int type) {// 这个Sapi.SpVoice是需要安装什么东西吗感觉平白无故就来了ActiveXComponent sap new ActiveXComponent(Sapi.SpVoice);// Dispatch是做什么的Dispatch sapo sap.getObject();if (type 0) {try {// 音量 0-100sap.setProperty(Volume, new Variant(100));// 语音朗读速度 -10 到 10sap.setProperty(Rate, new Variant(1.3));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(content));} catch (Exception e) {e.printStackTrace();} finally {sapo.safeRelease();sap.safeRelease();}} else {// 停止try {Dispatch.call(sapo, Speak, new Variant(content), new Variant(2));} catch (Exception e) {System.out.println(e.getMessage());e.printStackTrace();}}}/*** * Title: test* Description: 该方法的主要作用执行朗读内容* param 设定文件 * return 返回类型void * throws*/Testpublic void test(){strat(语音朗读的内容, 0);}}