TTS是Text To Speech的縮寫,即“從文本到語音”,讓機(jī)器能夠說話。
微軟自帶TTS(Text To Speech) 語音引擎,可以將文本轉(zhuǎn)換成語音播報(bào)。
現(xiàn)在通過Java程序(jacob包),利用Windows自帶的TTS實(shí)現(xiàn)語言的播報(bào)。
詳細(xì)步驟如下:
- 下載jacob jar包和dll文件
- 將dll放置到相應(yīng)的文件目錄中
- 將 jar包加入到工程中
- 執(zhí)行測試代碼
第一步:下載jacob jar包和dll文件。
從github的 jacob頁面連接 下載 jacob-1.20.zip,并解壓。
解壓后得到如下三個(gè)關(guān)鍵文件:
第二步:將 dll 放置到相應(yīng)的文件目錄中
將 文件jacob-1.20-x64.dll、jacob-1.20-x86.dll 拷貝到 C:\Windows\System32 目錄下。
第三步:將 jar包 加入到工程中。
第四步:執(zhí)行測試代碼。
代碼如下:文章來源:http://www.zghlxwxcb.cn/news/detail-466827.html
package com.lakala.zf.bs.iot.virtual.tts;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class TTSmain {
public static void main(String[] args) {
//調(diào)用windowsApi 的 com組件,Sapi.spVoice是 windows com組件名稱
ActiveXComponent activeXComponent = new ActiveXComponent("Sapi.SpVoice");
//從com組件中獲得調(diào)度目標(biāo)
Dispatch dis = activeXComponent.getObject();
try {
//設(shè)置語言組件屬性
activeXComponent.setProperty("Volume", new Variant(100));
activeXComponent.setProperty("Rate", new Variant(-1));
Dispatch.call(dis, "Speak", new Variant("今天天氣不錯(cuò),風(fēng)和日麗的。"));
}catch(Exception e){
e.printStackTrace();
}finally {
dis.safeRelease();
activeXComponent.safeRelease();
}
}
}
以上就是本文全部內(nèi)容,感謝耐心閱讀。文章來源地址http://www.zghlxwxcb.cn/news/detail-466827.html
到了這里,關(guān)于4個(gè)步驟實(shí)現(xiàn)Java版的TTS(文字轉(zhuǎn)語音)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!