useSpeechToText
Speech to text hook. Powered by the Web Speech API for speech recognition.
Experimental DO NOT use this hook in production.
Web Speech API may not be supported by all browsers. Browser
compatibility.
Import
Usage
Type Definition
Special Types
Name | Type | Description |
---|---|---|
UseSpeechToTextErrorCode | SpeechRecognitionErrorCode | Possible error codes that can be returned by the Web Speech API. Enum: SpeechRecognitionErrorCode . |
UseSpeechToTextOptions | See useSpeechToText Options below | useSpeechToText options. |
useSpeechToText
Options
Name | Type | Default | Description |
---|---|---|---|
lang | string | HTML lang attribute value | Language of the speech. If not specified, and the HTML lang attribute isn’t set either then the user agent’s language setting will be used. Read more. |
onStart | () => void | — | Callback function that is called when the speech recognition service has begun listening to incoming audio. |
onUnMatch | (event: SpeechRecognitionEvent) => void | — | Fired when the speech recognition service returns a final result with no significant recognition. |
onError | (event: SpeechRecognitionErrorEvent) => void | — | Fired when a speech recognition error occurs. |
Return Types
Name | Type | Description |
---|---|---|
isSpeechAPIAvailable | boolean | Flag to check if the Web Speech API is available. |
isListening | boolean | Is the service is listening to incoming audio or not. |
startListening | () => void | Turn on microphone and start listening. |
stopListening | () => void | Turn off microphone and stop listening. |
transcript | string | The result of the speech recognition. |