HTML5 的语音识别 API

HTML5's Speech Recognition API

我正在尝试使用 HTML5 的语音识别 API,但它没有得到我试图转换为文本的语音。它显示的不是我说的话,而是别的东西。请看看我的代码:

<script type = 'text/javascript'>

var recognition = new webkitSpeechRecognition();
recognition.continuous = false;
recognition.interimResults = true;
recognition.onresult = function(event) { 
  alert(event);
}

</script>

<input type = "submit" value = "Start Speaking" onclick = "recognition.start()">

提醒结果:

[object SpeechRecognizationEvent]

预期结果:

"Hello"

^^^我是这么说的

您可以阅读很多关于 webkitSpeechRecognition 的内容,您获得该对象的原因如下:

这给出了一个需要以这种方式处理的对象:

recognition.onresult = function(event) { 

   for (var i = event.resultIndex; i < event.results.length; ++i) { 
       var identificated = event.results[i][0].transcript;//This is what recognizes 
       if (event.results[i].isFinal) {
             console.log("Final sentence is : " + identificated );  
       }else{
           console.log("I understood : " + identificated );  
        }
}

1) 看官方演示Source Code Here

2) 或者在这里快速阅读(这是你需要的):Example of what you need

你可以测试我的库,是使用 webkitSpeechRecognition 的语音控制

Artyom Voice Recognition - Control