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
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
来源:https://stackoverflow.com/questions/43828361/how-to-capture-speech-except-command-in-annyang-speech-api