Composition and API
The Speech Synthesizer component wraps the browser's SpeechSynthesis API. It exposes speak, pause, resume, and stop methods via an imperative ref handle. The component provides onStart, onEnd, onError, and onStateChange callbacks for integrating speech synthesis into your application state.
Accessibility
The control buttons use aria-labels for screen readers. The component announces state changes via the onStateChange callback. Ensure you provide visual alternatives for speech output, and respect user preferences for reduced motion.
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 synthesis?
The SpeechSynthesis API is widely supported across Chrome, Firefox, Safari, and Edge. Voice availability varies by browser and operating system.
How do I change the voice?
Use the lang prop to set the language. The browser selects the default voice for the given locale. Custom voice selection is available via the underlying SpeechSynthesis API.
Can I control speed and pitch?
Yes. Use the rate prop (0.1 to 10, default 1) and pitch prop (0 to 2, default 1) to adjust speech characteristics.