JamesBrill / react-speech-recognition

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

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

Open davidli3100 opened 10 months ago

davidli3100 commented 10 months ago

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 10 months ago

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.