前言
我們提供的服務有:成都網(wǎng)站建設(shè)、做網(wǎng)站、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、秦州ssl等。為上千企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術(shù)的秦州網(wǎng)站制作公司
本文主要給大家分享了關(guān)于java文字轉(zhuǎn)語音播報的相關(guān)內(nèi)容,分享出來供大家參考學習,下面話不多說了,來一起看看詳細的介紹吧
方法如下
一、pom.xml引入jar包依賴
<!-- https://mvnrepository.com/artifact/com.jacob/jacob 文字轉(zhuǎn)語音 --> <dependency> <groupId>com.hynnet</groupId> <artifactId>jacob</artifactId> <version>1.18</version> </dependency>
二、把jacob-1.18-x64.dll文件復制到jdk安裝位置的bin目錄下。
https://files.cnblogs.com/files/w1441639547/jacob-1.18-x64.rar
三、把jacobtest.java類導入至項目中測試運行。
package com.Interface.util; import com.jacob.activeX.ActiveXComponent; import com.jacob.com.Dispatch; import com.jacob.com.Variant; /** * 文字轉(zhuǎn)語音測試 jdk bin文件中需要導入jacob-1.17-M2-x64.dll * * @author zk * @date: 2019年6月25日 上午10:05:21 */ public class jacobtest { /** * 語音轉(zhuǎn)文字并播放 * * @param txt */ public static void textToSpeech(String text) { ActiveXComponent ax = null; try { ax = new ActiveXComponent("Sapi.SpVoice"); // 運行時輸出語音內(nèi)容 Dispatch spVoice = ax.getObject(); // 音量 0-100 ax.setProperty("Volume", new Variant(100)); // 語音朗讀速度 -10 到 +10 ax.setProperty("Rate", new Variant(-2)); // 執(zhí)行朗讀 Dispatch.call(spVoice, "Speak", new Variant(text)); // 下面是構(gòu)建文件流把生成語音文件 ax = new ActiveXComponent("Sapi.SpFileStream"); Dispatch spFileStream = ax.getObject(); ax = new ActiveXComponent("Sapi.SpAudioFormat"); Dispatch spAudioFormat = ax.getObject(); // 設(shè)置音頻流格式 Dispatch.put(spAudioFormat, "Type", new Variant(22)); // 設(shè)置文件輸出流格式 Dispatch.putRef(spFileStream, "Format", spAudioFormat); // 調(diào)用輸出 文件流打開方法,創(chuàng)建一個.wav文件 Dispatch.call(spFileStream, "Open", new Variant("./text.wav"), new Variant(3), new Variant(true)); // 設(shè)置聲音對象的音頻輸出流為輸出文件對象 Dispatch.putRef(spVoice, "AudioOutputStream", spFileStream); // 設(shè)置音量 0到100 Dispatch.put(spVoice, "Volume", new Variant(100)); // 設(shè)置朗讀速度 Dispatch.put(spVoice, "Rate", new Variant(-2)); // 開始朗讀 Dispatch.call(spVoice, "Speak", new Variant(text)); // 關(guān)閉輸出文件 Dispatch.call(spFileStream, "Close"); Dispatch.putRef(spVoice, "AudioOutputStream", null); spAudioFormat.safeRelease(); spFileStream.safeRelease(); spVoice.safeRelease(); ax.safeRelease(); } catch (Exception e) { e.printStackTrace(); } } }
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對創(chuàng)新互聯(lián)的支持。
分享文章:java文字轉(zhuǎn)語音播報功能的實現(xiàn)方法
URL標題:http://jinyejixie.com/article48/joheep.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機網(wǎng)站建設(shè)、商城網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、域名注冊、網(wǎng)站收錄、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)