webkitSpeechRecognition on Android Chrome
Asked Answered
F

2

15

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));

          };

      }

enter image description here

Flattery answered 9/2, 2017 at 11:0 Comment(0)
F
6

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...

Figured answered 14/3, 2017 at 15:59 Comment(0)
E
-1

Try setting:

recognition.continuous = false

No guarantee but this worked for me running on Chrome on a Galaxy S7

Enrol answered 7/1, 2021 at 22:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.