forked from JamesBrill/react-speech-recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
52 lines (45 loc) · 1.56 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/// <reference types="dom-speech-recognition" />
interface Command {
command: string | string[] | RegExp;
callback: (...args: any[]) => unknown;
isFuzzyMatch?: boolean | undefined;
matchInterim?: boolean | undefined;
fuzzyMatchingThreshold?: number | undefined;
bestMatchOnly?: boolean | undefined;
}
export interface ListeningOptions {
continuous?: boolean | undefined;
interimResults?: boolean | undefined;
language?: string | undefined;
}
interface SpeechRecognition {
getRecognition(): globalThis.SpeechRecognition | null;
startListening(
options?: ListeningOptions & { onAudioStart?: () => void }
): Promise<void>;
stopListening(options?: { onAudioEnd?: () => void }): Promise<void>;
abortListening(): Promise<void>;
browserSupportsSpeechRecognition(): boolean;
applyPolyfill(speechRecognitionPolyfill: any): void;
}
export interface SpeechRecognitionOptions {
transcribing?: boolean | undefined;
clearTranscriptOnListen?: boolean | undefined;
commands?: readonly Command[] | undefined;
onAudioEnd?: () => void;
onAudioStart?: () => void;
onError?: (params: { error: string; message?: string }) => void;
}
export function useSpeechRecognition(options?: SpeechRecognitionOptions): {
transcript: string;
interimTranscript: string;
finalTranscript: string;
listening: boolean;
resetTranscript: () => void;
browserSupportsSpeechRecognition: boolean;
isMicrophoneAvailable: boolean;
onAudioEnd?: () => void;
onAudioStart?: () => void;
};
declare const SpeechRecognition: SpeechRecognition;
export default SpeechRecognition;