Javascript中的responsiveVoice API If语句不起作用

问题描述

我已经尝试让我的代码responsivevoice API 一起工作,但由于某种原因,它工作正常。它适用于“onclick”,但不适用于 if 语句。我究竟做错了什么?一切在我看来都是正确的,但它行不通。代码如下所示。

function record() {
 var recognition = new webkitSpeechRecognition();
 recognition.lang = "en-GB";
 recognition.start();
 recognition.onresult = function(event) {
   let transcript = event.results[0][0].transcript;
var str = transcript;
if (str.includes('test')) {
  responsivevoice.speak('This works!');
}
    document.getElementById('speechToText').value = event.results[0][0].transcript;
  }
}
<!DOCTYPE html>
<html lang="en">
<head>
   <Meta charset="UTF-8">
   <Meta name="viewport" content="width=device-width,initial-scale=1.0">
   <Meta http-equiv="X-UA-Compatible" content="ie=edge">
   <title>Document</title>
</head>
<body>
   <label for="Speech Recognition">Speech Recognition</label>
   <input type="text" name="" id="speechToText" placeholder="Speak Something" disabled="disabled">
   <button onclick="record()">Record</button>
   <p id="output"></p>
   <script src='https://code.responsivevoice.org/responsivevoice.js'></script>
   <script src="script.js"></script>
</body>
</html>

感谢您的帮助。我真的很感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)