2016-06-24 92 views
0

我在嘗試嵌入語音識別API,但下面的代碼失敗。控制不進入功能(事件)。有人可以幫助和建議。忽略HTML5語音識別回調

function startDictation() { 

    if (window.hasOwnProperty('webkitSpeechRecognition')) { 

    var recognition = new webkitSpeechRecognition(); 

    recognition.continuous = false; 
    recognition.interimResults = false; 

    recognition.lang = "en-US"; 
    recognition.start(); 

    recognition.onresult = function(event) { 

     document.getElementById('transcript').value = event.results[0][0].transcript; 
     console.log(event); 
     recognition.stop(); 
     document.getElementById('saurabh').submit(); 
    }; 

    recognition.onerror = function(event) { 
     console.log("Hello"); 
     console.log(recognition.onerror); 
     recognition.stop(); 
    } 

    } 
} 
+1

請分享html代碼以便調試 –

回答

0

您需要首先設置回調,然後撥打recognition.start()。在你的情況下,你開始識別而不設置回調。