WarningBrowser support is strictly limited to Google Chrome. Brave and Edge are explicitly filtered out due to inconsistent Speech API implementations.
ImportantThe start() method must be triggered by a user gesture (e.g., a click event) to comply with browser security policies regarding microphone access.
NoteThe hook includes an auto-restart mechanism for the no-speech error to keep the session alive unless stop() is called manually.
The useSpeech wraps the SpeechRecognition interface, allowing developers to convert audio from a microphone into real-time text strings. It handles cross-browser prefixes (e.g., webkitSpeechRecognition), manages internal state transitions (listening, stopped, error), and cleans up listeners automatically.
To avoid non-deterministic behavior, crashes, or infinite restart loops, this hook performs a runtime browser check and will not activate outside of Chrome.
| Name | Type | Description |
|---|---|---|
| options.continuous | boolean | If true, the recognition continues even if the user pauses. Default: false. |
| options.interimResults | boolean | If true, partial results are returned while the user is still speaking. Default: false. |
| options.lang | string | The BCP 47 language tag for the recognition (e.g., 'en-US'). Default: 'en-US'. |
| Name | Type | Description |
|---|---|---|
| error | Error | null | Contains the error object if recognition fails. |
| start | () => void | Function to initialize and start the speech recognition session. |
| status | SpeechStatus | Current status: 'idle', 'listening', 'stopped', 'unsupported', or 'error'. |
| stop | () => void | Stops the recognition process. |
| transcript | string | The accumulated text recognized from the speech input. |