react-speech-recognition icon indicating copy to clipboard operation
react-speech-recognition copied to clipboard

`AbortListening` is not a function when using the Azure Polyfill

Open davidli3100 opened this issue 2 years ago • 1 comments

When using the azure polyfill as described below, calling SpeechRecognition.abortListening raises an error since abort is not a function. Not sure if there's something funny going on with how I'm using the polyfill, or if we should be using stop instead

  useEffect(() => {
    if (typeof document !== "undefined") {
      const { SpeechRecognition: AzureSpeechRecognition } =
        createSpeechServicesPonyfill({
          credentials: async () => {
            const { data } = await axios.get("api/getSpeechKey");
            const { authToken } = data || {};
            return {
              region: "eastus",
              authorizationToken: authToken,
            };
          },
        });
      SpeechRecognition.applyPolyfill(AzureSpeechRecognition);
    }
  }, []);

davidli3100 avatar Aug 16 '23 23:08 davidli3100

This is probably a timing issue... I noticed the same problem recently if I try to:

  1. useSpeechRecognition
  2. StartListening
  3. AbortListening

Very quickly (within a few seconds, particularly if my internet connection is slow). If I wait for a bit longer, the function appears.

dkaser avatar Aug 24 '23 15:08 dkaser