2017-05-07 60 views

回答

0

我們可以通過使用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> 
0

您可以使用回調函數和結果捕獲整個語音。

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

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