【问题标题】:How to end a spoken sentence to page redirection, javascript如何结束口语到页面重定向,javascript
【发布时间】:2018-04-01 20:45:31
【问题描述】:

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

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

【问题讨论】:

    标签: javascript replace location constants sentence


    【解决方案1】:

    正如您已经说过的,此 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);
      }
    });
    

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

    【讨论】:

    • 音高只能从0到2,不能为负数
    • 感谢@SethStephens 的更正。我没有读过很多关于参数的允许值,只是签名,因为我认为这是原始问题的主要关注点。很抱歉“重复”你的答案,但是当我开始写这个问题时,还没有答案。
    【解决方案2】:

    要添加结束回调,您需要在选项对象中指定它,还必须在同一对象中提供所有选项。固定代码是

    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, // Your pitch can't be negative (according to the api docs)
        onend: () => {
          // enter code here
          // it will be called after the speaking is over
        }
    });
    

    查看ResponsiveVoice.JS API docs 以了解其他信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-16
      • 1970-01-01
      相关资源
      最近更新 更多