Web Speech API - Speech Recognition does not return alternatives in mobile

96 Views Asked by At

I am trying to implement Web Speech API - Speech Recognition in my web app with the following parameters:

    vSearch = new webkitSpeechRecognition();
    vSearch.continuous = false;
    vSearch.interimResults = false;
    vSearch.maxAlternatives = 5
    vSearch.lang = 'en-US';

This works both in desktop and mobile Chrome except one difference.

SpeechRecognitionAlternative array in the result list usually contains more than one entries in desktop (as expected) but it is always one in mobile and it seems like "vSearch.maxAlternatives = 5" directive is not taken into account.

What I realized on top of that is, if I put the phone in flight mode and try the same thing, I see multiple alternatives are being returned just like the desktop version. So it seems like the API is making an online call as default but fails to pass maxAlternatives option when making that call.

I couldn't find any documentation describing such behavior. That's why I wanted to check if anyone had a similar experience.

Thanks for your help in advance

Here is a minimal reproducible example. To demonstrate the issue run this snippet on desktop and mobile in the same browser.

const vSearch = new webkitSpeechRecognition();
vSearch.continuous = false;
vSearch.interimResults = false;
vSearch.maxAlternatives = 5;
vSearch.lang = "en-US";
vSearch.onresult = (result) => {
    console.log(result) 
}

vSearch.onstart = () => {
document.getElementById("listening").innerHTML = "listening"

}
vSearch.onend = () => {
document.getElementById("listening").innerHTML = "Not listening"

}

function testSpeech(){
    vSearch.start()
}
<html>
    <body>
        <button onclick="testSpeech()">Test Speech</button>
        <div id="listening">Not listening</div>
    </body>
</html>

0

There are 0 best solutions below