我在尝试将音频附加到提示符时遇到了困难,"你的名字是什么",音频" images / whatisyourname.wav"。我不知道如何附加这些两个不同的元素在一起
我已经在这个问题上工作了好几个小时,并且为了正确思考而感到沮丧。我根本不懂javascript,所以请,任何建议都是我不熟悉的语言。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>eve_</title>
<link rel="icon" rel="preload" href="images/evecircle.png" />
<style>
#video {
margin-left:-10px;
margin-top:-10px;
}
</style>
<script src="https://code.responsivevoice.org/responsivevoice.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<style type="text/css">
body {
overflow:hidden;
}
</style>
<body onload="delayedAlert();">
<script>
var timeoutID;
function delayedAlert() {
timeoutID = window.setTimeout(slowAlert, 3000);
}
function slowAlert() {
var audio= document.getElementsByTagName('audio')[0];
const audio2 = document.getElementsByTagName('audio')[1];
audio.play();
var myvar1;alert('...Hello?')
audio2.play();
var myvar2;alert('Hello?');
const name = prompt('What is your name?')
const sentence = 'Hello' + name +',I am Eve. What does a' +name +'look like?';
responsiveVoice.speak(sentence, "US English Female", {rate: 0.7});
}
</script>
<audio>
<source src="images/hellllloooo.wav" type="audio/wav" preload=true>
</audio>
<audio>
<source src="images/sorry.wav?.wav?.wav" type="audio/wav" preload=true>
</audio>
<audio>
<source src="images/whatisyourname.wav" type="audio/wav" preload=true>
</audio>
<video autoplay="autoplay" preload="auto" id="video" src="images/secondnew.mp4" width="1300px" height="auto" style="position:absolute; z-index:-1;" >
Video not supported.
</video>
</body>
</html>
答案 0 :(得分:1)
我认为此代码会对您有所帮助。我想你只是叫停止方法。
function slowAlert() {
var audio= document.getElementsByTagName('audio')[0];
var audio2 = document.getElementsByTagName('audio')[1];
var audio3 = document.getElementsByTagName('audio')[2];
audio.play();
var myvar1;alert('...Hello?')
audio.stop();
audio2.play();
var myvar2;alert('Hello?');
audio2.stop();
audio3.play();
const name = prompt('What is your name?')
audio3.stop();
const sentence = 'Hello' + name +',I am Eve. What does a' +name +'look like?';
responsiveVoice.speak(sentence, "US English Female", {rate: 0.7});
}
答案 1 :(得分:1)
您不需要将音频文件嵌入DOM中。这样的事情应该有效。你需要重构:
var promptAudio = new Audio('promp-sound.mp3');
promptAudio.volume = 1;
function promptSound() {
promptAudio.currentTime = 0;
promptAudio.play();
// call your alert
}
答案 2 :(得分:1)
如果您在提醒/提示某些内容的同时无法获得responsiveVoice,则必须使用回调,如下所示:
const name = prompt('What is your name?')
alertAndSpeak('Hello' + name +', I am Eve. What does a ' + name + ' look like?');
function alertAndSpeak(text) {
responsiveVoice.speak(text, "US English Female", {
rate: 0.7,
onstart: () => alert(text),
onend: null
});
}
&#13;
<script src="https://code.responsivevoice.org/responsivevoice.js"></script>
&#13;