繁体   English   中英

Javascript 中的 SetInterval 中的 ResponsiveVoice 代码:如何停止循环?

[英]ResponsiveVoice code within SetInterval in Javascript: How to stop the loop?

目前我正在做排队系统,我正在使用响应式语音进行语音播报。 我把它放在 setInterval 上,但问题是它在循环,声音永远不会停止。

     $( document ).ready(function() {
       setInterval(function() {
         $.ajax({
           url: "/getnewdata",
           cache: false,
         }).done(function(html) {
           $( '#data-container' ).html(html);
         });
         responsiveVoice.speak("{{ $new_call->letter }}-{{ $new_call->number }} please proceed to Counter {{ $new_call->counter_id }}")
       }, 3000);
    });

我只希望那个语音播音员只循环一次。 另一个问题,当新添加数据时,它应该宣布一个数据。 另一个问题不是例如“30 号”,而是“29 号”。

我试试这个

$( document ).ready(function() {
    setInterval(function() {
      $.ajax({
        url: "/getnewdata",
        cache: false,
      }).done(function(html) {
          $( '#data-container' ).html(html);
          setTimeout(function() {
            function voiceStartCallback() {
                console.log("Voice started");
            }

            function voiceEndCallback() {
                console.log("Voice ended");
            }

            var parameters = {
                onstart: voiceStartCallback,
                onend: voiceEndCallback
            }
            responsiveVoice.speak("{{ $new_call->letter }}-{{ $new_call->number }} please proceed to Counter {{ $new_call->counter_id }}", parameters)
          }, 800);
      });
    }, 3000);    
  });

当我查看控制台时出现错误:Uncaught TypeError: Cannot read property 'deprecated' of null at ResponsiveVoice.a.speak (responsivevoice.js?key=8PNDpxy8:117) at queue:178

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM