microsoft / cognitive-services-speech-sdk-js

Microsoft Azure Cognitive Services Speech SDK for JavaScript
Other
261 stars 95 forks source link

[Bug]: SpeechRecognizer for browsers not working on Android devices #846

Open OndrejUzovic opened 1 month ago

OndrejUzovic commented 1 month ago

What happened?

I have implemented a speech to text recognition from the microphone for browsers.

The implementation works perfectly fine if the browser is running on a desktop computer. However if the browser is executed on an Android mobile device the microphone is activated but no text is recognized - as if there is silence. No error is detected during that "silence".

Here is a short code to reproduce the issue:

function startSpeechRecognition(language) {
    const speechConfig = SpeechSDK.SpeechConfig.fromSubscription(key_xxx, sReg_yyy);
    speechConfig.speechRecognitionLanguage = language;
    const audioConfig = SpeechSDK.AudioConfig.fromDefaultMicrophoneInput();
    var myRecognizer = new SpeechSDK.SpeechRecognizer(speechConfig, audioConfig);
    myRecognizer.recognized = (recognizer, event) => {
        switch (event.result.reason) {
            case SpeechSDK.ResultReason.NoMatch:
                break;
            case SpeechSDK.ResultReason.RecognizedSpeech:
                onRecognizedText(speechConfig.speechRecognitionLanguage, event.result.text);
                break;
            case SpeechSDK.ResultReason.Canceled:
                const cancellation = SpeechSDK.CancellationDetails.fromResult(event.result);
                console.log(`CANCELED: Reason=${cancellation.reason}`);
                if (cancellation.reason == SpeechSDK.CancellationReason.Error) {
                    console.log(`CANCELED: ErrorCode=${cancellation.ErrorCode}`);
                    console.log(`CANCELED: ErrorDetails=${cancellation.errorDetails}`);
                }
                recognizer.stopContinuousRecognitionAsync();
                break;
        }
    };

    myRecognizer.startContinuousRecognitionAsync(() => { }, e => console.error(e));
}

I am using the SDK version 1.38.0 on Edge and Chrome browsers.

Is this is a bug or do I miss something?

Version

1.36.0 (Latest)

What browser/platform are you seeing the problem on?

Chrome

Relevant log output

No response

OndrejUzovic commented 1 month ago

I have debugged the code and it seems the problem is caused by the audio worklet. The callback: workletNode.port.onmessage() is never called on Android devices.

When the audio worklet is commented out, so that attachScriptProcessor() is called the speech to text started to work.

Please, could you provide a fix for the audio worklet or a possibility to turn it off?

chkrishna2001 commented 1 month ago

Hi any update on this ?

ubertanumutlu commented 1 week ago

The same problem persists and there seems to be no progress towards a solution.