JamesBrill / react-speech-recognition

💬Speech recognition for your React app
https://webspeechrecognition.com/
MIT License
657 stars 119 forks source link

Chrome on iOS not working #80

Closed waelmas closed 3 years ago

waelmas commented 3 years ago

It seems like speech recognition is not working on Chrome on iOS devices.

Not sure I'm doing something wrong but it seems like the fallback is triggered as if the browser did not support speech recognition at all.

    useEffect(() => {
        if (!SpeechRecognition.browserSupportsSpeechRecognition()) {
            return (() => {
                SpeechRecognition.stopListening();
                resetTranscript();
            })
        }
        if(microPhoneOn) {
              SpeechRecognition.startListening({continuous: true, language: "en"})
        }
        else {
            SpeechRecognition.stopListening();  
        }
        if(props.onTranscriptReceived) {
            props.onTranscriptReceived(messages);
        }       
        return (() => {
              SpeechRecognition.stopListening();
              resetTranscript();
        })
      }, [microPhoneOn, prevMessage]);
JamesBrill commented 3 years ago

Hi @waelmas It seems that the Web Speech API is not supported by iOS on any browser. So SpeechRecognition.browserSupportsSpeechRecognition() will return false on that platform. I will update the README to state this. There is a project to enable an AWS-based polyfill for the Web Speech API to enable it to work on unsupported browsers - you can follow its progress here.

Also, I recommend looking at the examples to see how you can consume this library. For browserSupportsSpeechRecognition, the pattern I'd recommend is to use it to render fallback content (or null), rather than using it in an effect hook.