1

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

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”。

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

4

0 回答 0