JamesBrill/react-speech-recognition

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

davidli3100 opened this issue · 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);
    }
  }, []);
dkaser commented

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.