环境搭建:
1.安装好所需要的语音库,官方语音库下载:http://www.microsoft.com/en-us/download/details.aspx?id=10121;
2.使用IE浏览器,并调整IE浏览器设置,设置访问站点为信任站点,并开启(对未标记为可安全执行脚本的ActiveX控件初始化并执行脚本)的选项;
Function CanSspeak(msg)
Set Sapi = CreateObject("SAPI.SpVoice")
Set Sapi.Voice = Sapi.GetVoices("Name=Girl XiaoKun").Item(0) '选择语音库,Girl XiaoKun为下载的私人语音库
Sapi.Rate = 5 '控制语速
Sapi.Volume = 100 '控制音量
Sapi.speak msg
End Function
把以上脚本嵌入到html文件中,然后利用脚本(js脚本也可)调用此脚本函数即可;
1.Win7/XP安装语音库,中英文女生语音库_TTS
2.在浏览器上把语音播报的URL设置为设为可信任站点,并对可信任站点做相应的设置(开启对未标记为可安全执行脚本的ActiveX控件初始化并执行脚本);
3.语音播报脚本如下:
<html>
<head>
<SCRIPT LANGUAGE="VBScript">
Function CanSspeak(msg)
Set Sapi = CreateObject("SAPI.SpVoice")
Set Sapi.Voice = Sapi.GetVoices("Name=Girl XiaoKun").Item(0) '选择语音库,Girl XiaoKun为下载的私人语音库
Sapi.Rate = 0 '控制语速
Sapi.Volume = 100 '控制音量
Sapi.speak msg
End Function
</SCRIPT>
<script LANGUAGE="JavaScript">
function point(){
var input=document.getElementById("input1");
CanSspeak(input.value);
}
</script>
</head>
<body>
<form action="" method="post">
<input type="text" id="input1">
<input type="button" name="but1" value="点击我,输入你想说的话" onclick="point()"/>
</form>
</body>
<html>
网友评论