Android webkitspeech . recognition . isfinal变量没有显示正确的值



我正在尝试在移动设备上做一些语音识别的东西。这里有一些代码…

var recognition = new webkitSpeechRecognition();
recognition.onresult = function (e) {
  //This is called every time the Speech Recognition hears you speak.
  //You may say "How's it going today", the recognition will try to 
  //interpret what you're saying while you're speaking. For example, while
  //you're speaking it may go.. "house" "how's it going" "how's it going today"
  //as it interprets it returns an object that contains properties, one of
  //which is "e.results[i].isFinal" where "i" is an array of returned objects.
  //In this case the object with a transcript of "house" would have a 
  //"e.results[i].isFinal" value of false. Where as the object with a transcript 
  //of "how's it going today" would have a "e.results[i].isFinal" value of 
  //true.. Because this is the FINAL INTERPRETATION of this particular transcript.
  //HOWEVER.. The problem I'm having is that when using a mobile device, the "e.results[i].isFinal" always
  //has a value of true, even when it's not the final interpretation. It works correctly on desktop however. Both are using Chrome. 
  if(e.results[e.results.length-1].isFinal){
      var finalTranscript = '';
      for(i=0;i<e.results.length;i++){
          finalTranscript += e.results[i][0].transcript;
      }
      console.log(finalTranscript);
      document.getElementById('output').innerHTML = finalTranscript;
  }
}

我只是想知道是否有人遇到过这个问题,以及如何解决这个问题。我在我的网站上有一个例子。

https://jaymartmedia.com/example/speech.html

我在页面上添加了一些调试信息(以便我可以在移动设备上"看到"控制台)。在桌面上,你会注意到"2:Final: false",有时会出现"2:Final: true"。这是"e.results[i]. isfinal"的值。在手机上,它总是(或者至少每次我在手机上尝试时)是"2:Final: true"。

这引起了重大问题,任何见解将不胜感激。

我找不到直接的解决方法。

但是在我的情况下,它解决了当我禁用所有中间结果时的错误:

var recognition = new webkitSpeechRecognition();
recognition.continuous = false
// or
recognition.interimResults = false

相关内容

  • 没有找到相关文章

最新更新