简体   繁体   中英

Google Chrome Speech-to-Text API JavaScript Continuous Doesn't Work?

I am creating a basic speech-to-text website. It only needs to work in Google Chrome, so I'm using the simple chrome speech-to-text API. It activates for a second and then disables. My code is simple:

    var recognition = new webkitSpeechRecognition();
    recognition.continuous = true;
    recognition.interimResults = true;
    final_transcript = '';
    recognition.onresult = function (event) {
        var interim_transcript = '';

        for (var i = event.resultIndex; i < event.results.length; ++i) {
            if (event.results[i].isFinal) {
                final_transcript += event.results[i][0].transcript;
            } else {
                interim_transcript += event.results[i][0].transcript;
            }
        }
        document.getElementById("write").value = final_transcript;
        recognition.start();
    };
    recognition.start();

For some reason, a problem occurs. It worked perfectly a day ago. All answers are appreciated!

我做了一个类似的任务,并通过调用来实现它recognition.stop()onresult处理器和recognition.start()onend处理程序。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM