如何在 annyang 语音中捕获命令以外的语音 api

How to capture speech except command in annyang speech api

我能够根据安养语中提供的指令执行动作api。 但我的问题是如何使用此 api 捕获命令以外的语音。

我需要我们从 google 演讲中获得的相同行为 https://www.google.com/intl/en/chrome/demos/speech.html

我们可以通过使用 annyang.getSpeechRecognizer()

获取识别对象来捕获语音而不是命令

请找到演示代码:-

<!DOCTYPE html>
<html>
  <head>
  <script src='//cdnjs.cloudflare.com/ajax/libs/annyang/2.6.0/annyang.min.js'></script>
<script>
  annyang.start();
  var recognition = annyang.getSpeechRecognizer();
  var final_transcript = '';
  recognition.interimResults = true;
    recognition.onresult = function(event) {
    var interim_transcript = '';
    final_transcript = '';
    for (var i = event.resultIndex; i < event.results.length; ++i) {
        if (event.results[i].isFinal) {
            final_transcript += event.results[i][0].transcript;
            console.log("final_transcript="+final_transcript);
            annyang.trigger(final_transcript); //If the sentence is "final" for the Web Speech API, we can try to trigger the sentence
        } else {
            interim_transcript += event.results[i][0].transcript;
            console.log("interim_transcript="+interim_transcript);
        }
    }

    document.getElementById('123').innerHTML =  'interim='+interim_transcript+'<br/>final='+final_transcript;
    console.log('interim='+interim_transcript+'|final='+final_transcript);
  };
</script>
</head>
<body>
<br/><br/>
 Annyang! Speech Test<br/><br/>
<div id='123'>
No results yet
 </div>
</body>

您可以使用回调函数和结果捕获整个语音。

annyang.addCallback('result', function(phrases) {
    console.log('Speech recognized. Possible sentences said:');
    console.log(phrases);
});

请查看:https://github.com/TalAter/annyang/issues/97