简体   繁体   English

在Firefox浏览器中,加载iFrame后,SpeechSynthesis会自行恢复。 这是SpeechSynthesis的限制吗?

[英]SpeechSynthesis resumes on its own when iFrame is loaded, in firefox browser. Is that a limitation of SpeechSynthesis?

I am using speechSynthesis web api in my web application, I have created one toggle button which starts, pauses and resumes speechSynthesis. 我在网络应用程序中使用了SpeechSynthesis网络api,我创建了一个切换按钮,该按钮可以启动,暂停和继续SpeechSynthesis。 Also I have created one more button which sets a source to an Iframe. 另外,我还创建了一个按钮,用于将iframe设置为来源。

While running the app in firefox browser speechSynthesis is resuming on its own when I set a source to an Iframe. 在Firefox浏览器中运行该应用程序时,当我将源设置为iframe时,语音合成将自行恢复。

Here's my code (index.hrml): 这是我的代码(index.hrml):

<html>
<head>
  <script>
    var btnState = 'Start';
    var ttsState = 'completed';
    function toggleTTS() {
      if (btnState === 'Start') {
        if (ttsState === 'completed') {
          StopTTS();
          ttsState = 'started';
          speak(document.getElementById("speakText").innerText);
          document.getElementById('toggleBtn').innerHTML = "Pause";
        } else {
          ResumeTTS();
        }
        btnState = 'Stop';
      } else {
        PauseTTS();
        btnState = 'Start';
        document.getElementById('toggleBtn').innerHTML = "Resume";
      }
    }
    function StopTTS() {
      speechSynthesis.cancel();
    }
    function PauseTTS() {
      if (!speechSynthesis.paused && speechSynthesis.pause) {
        speechSynthesis.pause();
      }
    }
    function ResumeTTS() {
      if (speechSynthesis.pending || speechSynthesis.paused) {
        speechSynthesis.resume();
      }
    }
    function speak(text) {
      var u = new SpeechSynthesisUtterance(text);
      u.lang = 'en-US';
      u.onend = (e) => {
        console.log('completed')
        ttsState = 'completed';
        btnState = 'Start';
        document.getElementById('toggleBtn').innerHTML = "Speak";
      };
      speechSynthesis.speak(u);
    }
    function setSrc(){
      document.getElementById('dummyIframe').src = "index.html";
    }
  </script>
</head>
<body>
  <button id="toggleBtn" onclick="toggleTTS()">Speak</button>
  <button id="setSrcBtn" onclick="setSrc()">SetSrc</button>
  <div id="speakText">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
  <iframe id="dummyIframe"></iframe>
</body>
<html>

Steps to reproduce the bug: 重现该错误的步骤:

  1. Start speechSynthesis by clicking on "Speak" button and pause it in between. 通过单击“语音”按钮来启动语音合成并在其间暂停。
  2. Now set a source to an iframe by clicking "setSrc" button. 现在,通过单击“ setSrc”按钮将源设置为iframe。

Expected result : SpeechSynthesis should remain in pause state. 预期结果 :SpeechSynthesis应该保持在暂停状态。

Actual result : SpeechSynthesis resumes on its own in firefox browser. 实际结果 :SpeechSynthesis在firefox浏览器中自行恢复。

Note: This is only happening in firefox browser not on any other browsers. 注意:这仅在firefox浏览器中发生,而不在其他任何浏览器上发生。

On your html2 script remove if(elem !== null) elem.parentNode.removeChild(elem); 在您的html2脚本上,删除if(elem!== null)elem.parentNode.removeChild(elem);

Same file add this to the end: 同一文件将其添加到末尾:

document.addEventListener('DOMContentLoaded', () => {
  show2();
  show1();
});

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

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