useSpeechRecognition ​
sensors
test coverage
Last changed: 2 days ago
TIP
This hook uses window.SpeechRecognition browser api to provide enhanced functionality. Make sure to check for compatibility with different browsers when using this api
Hook that provides a streamlined interface for incorporating speech-to-text functionality
typescript
import { useSpeechRecognition } from '@siberiacancode/reactuse';
Usage ​
typescript
const { supported, value, recognition, listening, error, start, stop, toggle } = useSpeechRecognition();
Demo ​
Api ​
Parameters
Name | Type | Default | Note |
---|---|---|---|
options.continuous? | boolean | false | Whether recognition should continue after pauses |
options.interimResults? | boolean | false | Whether interim results should be provided |
options.language? | string | "en-US" | The language for recognition, as a valid BCP 47 tag |
options.maxAlternatives? | number | 1 | The maximum number of alternative transcripts to return |
options.grammars? | SpeechGrammarList | - | A list of grammar rules |
options.onStart? | () => void | - | Callback invoked when speech recognition starts |
options.onEnd? | () => void | - | Callback invoked when speech recognition ends |
options.onError? | (error: SpeechRecognitionErrorEvent) => void | - | Callback invoked when an error occurs during recognition |
options.onResult? | (event: SpeechRecognitionEvent) => void | - | Callback invoked when recognition produces a result |