0

次のコードを使用して、Chrome 27 で Web Speech API を使用しようとしています -

$(function(){
    initRecognition();
});

function initRecognition(){
    if(window.recognition !== undefined){
        window.recognition.stop();
        window.recognition.start();
        // ^--- Exception is being thrown at this line
    }else{
        window.recognition = new webkitSpeechRecognition();
        window.recognition.onresult = function(event) {
          if (event.results.length > 0) {
            command.value = event.results[0][0].transcript;
            return execute();
          }else{
            command.value = "*&#^$&@^#?";
            return execute();
          }
        };
        window.recognition.continuous = true;
        window.recognition.start();
    }
}

function execute(){
    // some code
    initRecognition();
    return false;
}

ページが読み込まれると、認識を開始する許可を求められます。1 つの単語またはフレーズを認識し、次のエラーで停止します -

Uncaught Error: InvalidStateError: DOM Exception 11
initRecognition
execute
window.recognition.onresult

そのためのリソースが不足しているようです。そのため、トラブルシューティングに問題があります。何か案が?

4

1 に答える 1