react-voice-to-text
Version:
A small lib to use the speech recognition api in react
33 lines (32 loc) • 1.3 kB
TypeScript
export interface SpeechRecognitionOptions {
onStart?: () => void;
onResult?: (event: SpeechRecognitionEvent) => void;
onEnd?: (lastText: string, transcriptHistory: string[]) => void;
onStop?: () => void;
onError?: (error: Error) => void;
throwOnUnsupported?: boolean;
lang?: string;
interimResults?: boolean;
maxAlternatives?: number;
}
export interface SpeechRecognitionEvent extends Event {
results: SpeechRecognitionResultList;
}
type SpeechRecognitionEventListener = ((eventName: 'error', callback: (event: Error) => void) => void) & ((eventName: 'start' | 'result' | 'end', callback: (event: SpeechRecognitionEvent) => void) => void);
type Recognition = {
lang: string;
interimResults: boolean;
maxAlternatives: number;
addEventListener: SpeechRecognitionEventListener;
start: () => void;
stop: () => void;
};
export interface SpeechRecognitionHandles {
startRecording: () => void;
stopRecording: () => void;
}
export declare function isSpeechRecognitionSupported(): boolean;
export declare function useSpeechRecognition({ throwOnUnsupported, onStart, onResult, onEnd, onStop, onError, lang, interimResults, maxAlternatives }?: SpeechRecognitionOptions): SpeechRecognitionHandles & {
recognition: Recognition;
};
export {};