方法一:(推薦)
function BtnGZ(){
/*語音提示*/
var msg = new SpeechSynthesisUtterance("個人工資數據展示");
window.speechSynthesis.speak(msg);
document.location.href='/swj_salary/personSalary/index.do';
將 /*語音提示*/
var msg = new SpeechSynthesisUtterance("個人工資數據展示");
window.speechSynthesis.speak(msg);
放在方法中,或者<script> /*語音提示*/ XXX</<script>
speechSynthesis 接口
speak
(SpeechSynthesisUtterance)- 這個方法應該傳遞一個實例SpeechSynthesisUtterance。然後它會將此添加到需要說出的話語隊列中。cancel()
- 此方法將從隊列中刪除所有話語。如果當前正在說話,那麼它將被停止。pause()
- 此方法將立即暫停正在講話的任何話語。resume()
- 此方法將使瀏覽器恢復說出先前暫停的話語。getVoices()
- 此方法返回瀏覽器支持的所有語音的列
speechSynthesis屬性 默認是false
pending
-true
如果隊列中有尚未開始說話的話語。speaking
-true
如果當前正在說話。paused
-true
如果當前暫停了話語。
SpeechSynthesisVoice 屬性
name
- 描述語音的人類可讀名稱。voiceURI
- 指定該語音的語音合成服務的位置的URI。lang
- 此語音的語言代碼。default
-true
如果這是瀏覽器使用的默認語音,則設置爲。localService
- API可以使用本地和遠程服務來處理語音合成。如果此屬性設置爲true語音合成,則此語音由本地服務處理。如果false是正在使用的遠程服務。
方法二:
Jacob包,或者使用maven導入jacob標籤(沒試過百度一下)
導入包需要的all,jacob.xxx.dll
1.將jacob.xxx.dll 按照32位,64位複製到jdk/bin目錄下
2.將jacob.xxx.dll 複製到winx86、或64位,我的是64位 C:\Windows\SysWOW64
3.將Jacob.jar 複製到lib,記得奶一口,(buildpath)
package cn.apcinfo.test;
import java.util.Scanner;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");
Dispatch sapo = sap.getObject();
Dispatch.call(sapo, "Speak", new Variant("今天天氣好晴朗!"));
try {
// 音量 0-100
sap.setProperty("Volume", new Variant(100));
// 語音朗讀速度 -10 到 +10
sap.setProperty("Rate", new Variant(0));
System.out.println("請輸入要朗讀的內容:");
Scanner scan = new Scanner(System.in);
String str = scan.next();
// 執行朗讀
Dispatch.call(sapo, "Speak", new Variant(str));
} catch (Exception e) {
e.printStackTrace();
} finally {
sapo.safeRelease();
sap.safeRelease();
}
}
}
方法很多還可以使用百度api什麼的,找到適合自己的就好