Composition and API
The Speech Recognition component wraps the browser's SpeechRecognition API (webkitSpeechRecognition on Chromium). It exposes start, stop, and abort methods via an imperative ref handle. The component provides onResult, onError, and onStateChange callbacks for integrating speech results into your application state.
Accessibility
The microphone toggle button uses aria-label and aria-pressed attributes to convey listening state. Status text updates in real time. Ensure you provide visible labels and fallback input methods for users who cannot or choose not to use voice input.
Next.js integration notes
The Web Speech API is browser-only. Import the component via dynamic import with ssr: false to avoid server-side errors. The component handles SSR safety internally with a typeof window guard, but dynamic import is recommended for Next.js apps.
FAQ
Which browsers support speech recognition?
The Web Speech API is supported in Chromium-based browsers (Chrome, Edge, Brave). Firefox and Safari have limited or no support. Always provide a fallback for unsupported browsers.
Does the component require a microphone permission?
Yes. The browser will prompt the user for microphone access when speech recognition starts. The component handles permission errors via the onError callback.
Can I use multiple languages?
Yes. Set the lang prop to any BCP 47 language tag (e.g., 'en-US', 'es-ES', 'fr-FR'). The browser will use the language for recognition.