Android webkitSpeechRecognition .isFinal变量未显示正确的值

时间:2016-09-06 03:57:29

标签: javascript android speech-recognition speech-to-text webkitspeechrecognition

我试图在手机上做一些语音识别。这是一些代码..

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

我在页面上添加了一些调试信息(这样我就可以&#34;在移动设备上看到&#34;控制台。在桌面上你会注意到&#34; 2:最终:假&#34;有时&#34; 2:最终:真实&#34;。这是&#34; e.results [i] .isFinal&#34;的价值。在移动设备上它总是(或至少每次我&#39;我已经在手机上试过了吗?&#34; 2:最终:真实&#34;。

它会导致重大问题,我们将非常感谢任何见解。

0 个答案:

没有答案