webkitSpeechRecognition on Android Chrome

你说的曾经没有我的故事 提交于 2020-08-02 07:28:06

问题


I'm using a simple Speech to text detection with webkitSpeechRecognition. This code works great on Windows Desktop. But - on Android Chrome browser - When starting detection, the microphone on the Android status bar shows only for 1 or 2 seconds. If there is no voice activity - it turns off and the voice recognition stops. If I do speak very fast after clicking "Start", it stays on. Any ideas how to make the Android microphone available at all time?

     if ('webkitSpeechRecognition' in window) {

          var recognition = new webkitSpeechRecognition();

            recognition.continuous = true;
            recognition.interimResults = true;

            recognition.onstart = function () {
                $("#status").html("Status: Recording...");
                recognizing = true;
            };

            recognition.onerror = function (event) {
                alert(event.error);
            };

            recognition.onend = function() {
                recognizing = false;
            };

          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;
              }
            }
            final_transcript = capitalize(final_transcript);
            $("#final_span").html(linebreak(final_transcript));
            $("#interim_span").html(linebreak(interim_transcript));

          };

      }


回答1:


I looked for a solution to this myself as I am trying to build a hands-free interaction with WebVR.

https://codepen.io/bryik/pen/mErOOR?editors=0010 at least only beeps once, but after a bit of testing I noticed, that the 'beep' for recognition triggers again on every click/tap.

An older resource gave me good hope, that annyang (https://github.com/TalAter/annyang) might work:

https://github.com/cvan/webvr-holodeck/issues/22 But here I guess it's also only calling

recognition.onend = function() {
    console.info("voice recognition ended, restarting...");
    recognition.start();
}

in the recognition.onend callback. So on android chrome you might encounter recognition beeps every other second...

In the end, MDN doesn't really state if it's possible to have continuous recognition on android chrome (https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition), but every example I looked at didn't quite offer continuous mode on android (at least on CyanogenMod Lollipop)

// edit if you have a look at https://www.microsoft.com/cognitive-services/en-us/speech-api , they somehow manage to have continuous recognition but I can't find anything in their source code...



来源:https://stackoverflow.com/questions/42134899/webkitspeechrecognition-on-android-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!