java文字转语音教程

java文字转语音教程

保证项目正常,需要如下操作(如已完成,请忽略)

1.需要将项目中的jacob-1.14.3-x64_jb51.net.rar解压,

2.64位系统将解压得到的jacob-1.14.3-x64.dll放到jdk/bin下(64位系统)

项目映入依赖

<dependencies>

<dependency>

<groupId>net.sf.jacob-project</groupId>

<artifactId>jacob</artifactId>

<version>1.14.3</version>

</dependency>

</dependencies>

代码:

/**

*

*/

package pers.wwz.easyaccess;

import com.jacob.activeX.ActiveXComponent;

import com.jacob.com.Dispatch;

import com.jacob.com.Variant;

/**

* @author 作者 :wangwenzhe

* @createTime 创建时间:2018年12月23日 下午2:55:24

* @email 邮箱:[email protected]

* @desc

*/

public class WordsToSpeech {

public static void main(String[] args) {

ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");

Dispatch sapo = sap.getObject();

try {

// 音量 0-100

sap.setProperty("Volume", new Variant(10));

// 语音朗读速度 -10 到 +10

sap.setProperty("Rate", new Variant(2));

// 执行朗读

Dispatch.call(sapo, "Speak", new Variant("重要的事情说三遍!重要的事情说三遍!重要的事情说三遍!"));

} catch (Exception e) {

e.printStackTrace();

} finally {

sapo.safeRelease();

sap.safeRelease();

}

}

}

项目码云地址:https://gitee.com/WangZhe168/texttospeech_java.git

猜你喜欢

转载自blog.csdn.net/wangwenzhe222/article/details/85259321