JamesBrill / react-speech-recognition

đź’¬Speech recognition for your React app
https://webspeechrecognition.com/
MIT License
645 stars 116 forks source link

Get transcript on chrome desktop but not on Chrome Android & isMicrophoneAvailable returns undefined #130

Closed vaismav closed 1 year ago

vaismav commented 2 years ago

Hi :) So the code works great on Chrome desktop, but when I use it on a mobile device (with Chrome Android) the transcript stays empty.

while trying to solve this I've noticed isMicrophoneAvailable returns undefined consistently.

I do hear an occasional beeping sound indicating speech recognition is working (as mentioned in the docs) but other than that, nothing else.

I don't know if polyfill will solve this. I need to transcribe Hebrew, so I cant use Speechly, and currently, I don't want to spend credits on it so I cant use Microsoft. if it relates I will simply disable the transcription on mobile devices but thought it will be worth a shot to ask here :)

is it related to #129 in terms of the Chrome android?

the code:

import React, { useEffect, useRef } from 'react';
import SpeechRecognition, { useSpeechRecognition } from 'react-speech-recognition';

const SpeechRecognitionTest = () => {

    const transcriptRef = useRef();

    const {
        transcript,
        browserSupportsSpeechRecognition,
        listening,
        isMicrophoneAvailable,
    } = useSpeechRecognition();

    useEffect( () => {
        console.log('listening state: ', listening);
        console.log('is microphone availble: ', isMicrophoneAvailable);
        console.log('browserSupportsSpeechRecognition: ', browserSupportsSpeechRecognition);
        console.log("length", transcript.length);
        console.log(transcript);
    }, [listening,transcript]);

    useEffect(() => {
        if (!browserSupportsSpeechRecognition) {
            console.log("Browser doesn't support speech recognition!");
        }

        SpeechRecognition.startListening({ language: 'he', continuous: true })
                            .then( ()=> console.log('start listening for speech recognition. '))
                            .catch(e => console.log('failed to start listening for speech recognition. Err:',e));

        return () => {
            SpeechRecognition.abortListening();
        }

    }, []);

    return (<div/>);
};

export default SpeechRecognitionTest;

I was running the app and speaking for half minute and those are the outputs:

output on mobile:

listening state: false is microphone availble: undefined browserSupportsSpeechRecognition: true length 0

start listening for speech recognition. undefined listening state: true is microphone availble: undefined browserSupportsSpeechRecognition: true length 0

output on desktop:

test.js:17 listening state: false test.js:18 is microphone availble: undefined test.js:19 browserSupportsSpeechRecognition: true test.js:20 length 0 test.js:21 test.js:30 start listening for speech recognition. undefined test.js:17 listening state: true test.js:18 is microphone availble: undefined test.js:19 browserSupportsSpeechRecognition: true test.js:20 length 0 test.js:21 test.js:17 listening state: true test.js:18 is microphone availble: undefined test.js:19 browserSupportsSpeechRecognition: true test.js:20 length 1 test.js:21 1 test.js:17 listening state: true test.js:18 is microphone availble: undefined test.js:19 browserSupportsSpeechRecognition: true test.js:20 length 3 test.js:21 חדש test.js:17 listening state: true test.js:18 is microphone availble: undefined test.js:19 browserSupportsSpeechRecognition: true test.js:20 length 2 test.js:21 12 test.js:17 listening state: true test.js:18 is microphone availble: undefined test.js:19 browserSupportsSpeechRecognition: true test.js:20 length 3 test.js:21 126 test.js:17 listening state: true test.js:18 is microphone availble: undefined test.js:19 browserSupportsSpeechRecognition: true test.js:20 length 5 test.js:21 1 2 3 test.js:17 listening state: true test.js:18 is microphone availble: undefined test.js:19 browserSupportsSpeechRecognition: true test.js:20 length 7 test.js:21 1 2 3 4

Mobile device: Redmi 9 Android 10 Chrome App version 96.0.4664.45

Hope there is a nice solution :)

JamesBrill commented 2 years ago

Hi @vaismav Thanks for raising this issue! Some comments: