javascript - 如何结束页面重定向的口头句子,javascript

标签 javascript replace location constants sentence

如何在口头反馈后进行页面重定向,

"const sentence = 'Oh Hello,' + name +'.I am Eve. ....'+name +'= human?!..Ive never seen one of those...What does' +name +' look like?';
responsiveVoice.speak(sentence, "US English Female", {rate: 0.5}, {pitch: -2});"

整个句子完成后,我需要立即重定向网站 https://www.google.com/

我想我需要插入这段代码才能让它工作,就是这样;

video.addEventListener('ended',function(){
        location.replace ('http://www.google.com'),

但我根本不懂 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];
 var audio3 = document.getElementsByTagName('audio')[2];
  var audio4 = document.getElementsByTagName('audio')[3];

audio.play(); 
var myvar1;alert('....Hello?');

audio2.play(); 
var myvar1;alert('Something is here.');

audio3.play();
var myvar2;alert('Hello?');

audio4.play();

const name = prompt('What is your name?')

const sentence = 'Oh Hello,' + name +'.I am Eve. ....'+name +'= human?!..Ive never seen one of those...What does' +name +' look like?';
responsiveVoice.speak(sentence, "US English Female", {rate: 0.5}, {pitch: -2});
}


</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/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>

最佳答案

正如您已经说过的,此 API 的 speak 函数中有一些选项。但是,正如我们在 documentation 中看到的那样,你可能用错了。

至少,我从中得到的是,您需要传递一个对象作为第三个参数,指定所有选项(不是每个选项一个对象,如示例代码所示),如下所示:

responsiveVoice.speak("hello world", "UK English Male", { rate: 0.5, pitch: 1 });

还有一个选项onend,这是一个回调,当它完成句子时将被调用(或者至少声明库是这样操作的)。所以你可以这样做:

responsiveVoice.speak("hello world", "UK English Male", {
  rate: 0.5,
  pitch: 1,
  onend: function() {
    // Redirect after sentence has been spoke
    location.replace('http://www.google.com');
  }
});

例如,如果您需要延迟重定向操作,您可以随时使用 setTimeout 等在一段时间后执行此操作,如下所示:

responsiveVoice.speak("hello world", "UK English Male", {
  rate: 0.5,
  pitch: 1,
  onend: function() {
    // Redirect 2 seconds after sentence has been spoke
    // (the 2000 is the number of milliseconds to wait)
    setTimeout(function() {
      location.replace('http://www.google.com');
    }, 2000);
  }
});

希望对您有帮助!祝你好运!

关于javascript - 如何结束页面重定向的口头句子,javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49602454/

相关文章:

java - 我有一个打开 GUI 的按钮,如何设置 GUI 在屏幕上显示的位置?

iOS 模拟器自定义位置问题

ios - startMonitoringForRegion 与 startMonitoringSignificantLocationChanges

javascript - knockout 切换嵌套项目的可见性

在循环中跨列替换多个值

regex - 在 Notepad++ 中多行搜索和替换每行的开头和结尾

c - 无法用另一个字符串替换字符串中的字符

javascript - 如何从 Chrome 扩展调用网站的功能?

javascript - 使用 Jquery 搜索和隐藏文本

javascript - knockout 检查绑定(bind)不更新