Skip to content

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

import {useSpeechToText} from '@kaiverse/k/hooks'

Usage

Type Definition

function useSpeechToText(options: UseSpeechToTextOptions): {
isSpeechAPIAvailable: boolean
isListening: boolean
startListening: () => void
stopListening: () => void
transcript: string
}

Special Types

NameTypeDescription
UseSpeechToTextErrorCodeSpeechRecognitionErrorCodePossible error codes that can be returned by the Web Speech API. Enum: SpeechRecognitionErrorCode.
UseSpeechToTextOptionsSee useSpeechToText Options belowuseSpeechToText options.

useSpeechToText Options

NameTypeDefaultDescription
langstringHTML lang attribute valueLanguage 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() => voidCallback function that is called when the speech recognition service has begun listening to incoming audio.
onUnMatch(event: SpeechRecognitionEvent) => voidFired when the speech recognition service returns a final result with no significant recognition.
onError(event: SpeechRecognitionErrorEvent) => voidFired when a speech recognition error occurs.

Return Types

NameTypeDescription
isSpeechAPIAvailablebooleanFlag to check if the Web Speech API is available.
isListeningbooleanIs the service is listening to incoming audio or not.
startListening() => voidTurn on microphone and start listening.
stopListening() => voidTurn off microphone and stop listening.
transcriptstringThe result of the speech recognition.