自动播放语音教程
自动播放语音教程,可以在电脑端和手机端可以实现打开网页自动播放语音声音。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>自动播放声音(手机+电脑端)</title>
</head>
<body>
<%
response.addheader "Content-Type", "text/html; charset=utf-8"
dim qr,nLen
qr=request("cxid")
nLen=instr(qr,"?cxid=")
if nLen>0 then
qr=mid(qr,nLen+6)
end if
'处理播音'
function handlePlayTxt(c,cxid)
dim i,qr,url
qr=cxid
for i=0 to 9
qr=replace(qr,i,i &" ")
next
c=replace(c,cxid,qr)
url="https://ss0.baidu.com/6KAZsjip0QIZ8tyhnq/text2audio?tex="& c &"&cuid=dict&lan=zh&ctp=1&pdt=30&vol=100&spd=5"
handlePlayTxt="<audio id=""fw_voice"" style=""display:none"" src="""& url &""" autoplay="""" preload=""auto"">您的浏览器不支持 audio 标签。 controls</audio>"
'<audio id="fw_voice" style="display:none" class="media-audio" autoplay="" preload="auto"'
end function
%>
<a href='?qr=123456789'>查询123456789</a><br>
<div id="txt">您查询的防伪码:<%=qr%>已被多次查询过</div>
<%=handlePlayTxt(" 您查询的防伪码:"& qr &"已被多次查询过 ",qr)%>
<script src="jquery.min.js"></script>
<script type="text/javascript">
function PlayFwVoice(url) {
var music = document.getElementById('fw_voice');
var zhText = url;
// console.log(zhText)
var voicebbUrl = "https://ss0.baidu.com/6KAZsjip0QIZ8tyhnq/text2audio?tex=" + zhText + "&cuid=dict&lan=zh&ctp=1&pdt=30&vol=100&spd=5";
// console.log(voicebbUrl);
// $('#fw_voice').attr('src', voicebbUrl)
// var music = $('#fw_voice').get(0);
music.src = voicebbUrl;
setTimeout(function () {
music.play();
}, 500);
// document.addEventListener('touchstart', function () {
// music.play();
// });
// document.addEventListener("WeixinJSBridgeReady", function () {
// music.play();
// });
}
PlayFwVoice($("#txt").text());
</script>
</body>
</html>
下载案例
预览效果