← all repositories
JamesBrill/react-speech-recognition

A React hook that actually listens to you

Wraps the browser's Web Speech API into a hook so your components can transcribe microphone input without managing the global state themselves.

839 stars JavaScript Image · Video · Audio
react-speech-recognition
Velocity · 7d
+0.2
★ / day
Trend
steady
star history

What it does

useSpeechRecognition is a React hook that pipes microphone audio through the browser’s Web Speech API and hands you back a transcript, plus booleans for whether it’s currently listening and whether the browser even supports speech recognition. A separate SpeechRecognition object manages the global microphone state—start, stop, abort—across all components.

The interesting bit

The library is essentially a thin, well-shaped wrapper around a notoriously flaky API. The useful work happens in the escape hatches: it explicitly supports polyfills (Azure Cognitive Services is documented) so you can bypass Chrome’s monopoly on decent speech recognition, avoid shipping voice data to Google, and get consistent behavior across browsers. That’s the part most “just use the platform” tutorials skip.

Key highlights

  • Hook returns transcript, listening, resetTranscript, browserSupportsSpeechRecognition, and isMicrophoneAvailable
  • Command matching built-in: exact string/regex matches, plus optional fuzzy matching for misheard phrases
  • Global microphone state managed outside React’s tree via SpeechRecognition.startListening() and friends
  • Polyfill support documented for Azure; without one, you’re mostly stuck on Chrome, Edge, and Safari 14.1+
  • Requires React 16.8+; v2.x exists for legacy React

Caveats

  • Native support is genuinely thin outside Chrome-family browsers; the README is upfront that you’ll want a polyfill for anything serious
  • Android Chrome beeps at you when the mic turns on—OS-level behavior, not fixable from the browser
  • No polyfill is bundled; you bring your own (and your own cloud credentials)

Verdict

Grab this if you need voice commands or transcription in a React app and don’t want to hand-roll Web Speech API state management. Skip it if you need universal browser support without paying for a speech API, or if your users are mostly on Firefox.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.