How to capture speech except command in annyang speech api

老子叫甜甜 提交于 2019-12-08 04:26:02

问题


I am able to perform action according to commands provided in annyang speech api. But my question is how to capture speech except commands using this api.

I need the same behavior that we got from google speech https://www.google.com/intl/en/chrome/demos/speech.html


回答1:


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>



回答2:


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



来源:https://stackoverflow.com/questions/43828361/how-to-capture-speech-except-command-in-annyang-speech-api

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