代码之家  ›  专栏  ›  技术社区  ›  frosty

HTML5的语音识别API

  •  -1
  • frosty  · 技术社区  · 9 年前

    我正在尝试使用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"
    

    ^^^我就是这么说的。

    1 回复  |  直到 9 年前
        1
  •  1
  •   Carlos Delgado    9 年前

    有很多关于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