How to capture speech except command in annyang speech api

霸气de小男生 提交于 2019-12-06 19:54:29

We can capture the speech instead of command by getting the recognition object by using annyang.getSpeechRecognizer()

Please find the demo code :-

<!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>
gPats

You can capture the whole speech using callback function and result.

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

please check out: https://github.com/TalAter/annyang/issues/97

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!