-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.ts
67 lines (61 loc) · 2 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {
NativeModulesProxy,
EventEmitter,
Subscription,
PermissionResponse,
} from "expo-modules-core";
// Import the native module. On web, it will be resolved to ExpoStt.web.ts
// and on native platforms to ExpoStt.ts
import {
OnSpeechResultEventPayload,
OnSpeechErrorEventPayload,
ReactEvents,
} from "./ExpoStt.types";
import ExpoSttModule from "./ExpoSttModule";
export function startSpeech(): boolean {
return ExpoSttModule.startSpeech();
}
export function stopSpeech(): void {
return ExpoSttModule.stopSpeech();
}
export function cancelSpeech(): void {
return ExpoSttModule.cancelSpeech();
}
export function destroySpeech(): void {
return ExpoSttModule.destroySpeech();
}
export function requestRecognitionPermission(): Promise<PermissionResponse> {
return ExpoSttModule.requestRecognitionPermission();
}
export function checkRecognitionPermission(): Promise<PermissionResponse> {
return ExpoSttModule.checkRecognitionPermission();
}
const emitter = new EventEmitter(ExpoSttModule ?? NativeModulesProxy.ExpoStt);
export function addOnSpeechStartListener(listener: () => void): Subscription {
return emitter.addListener<void>(ReactEvents.onSpeechStart, listener);
}
export function addOnSpeechEndListener(listener: () => void): Subscription {
return emitter.addListener(ReactEvents.onSpeechEnd, listener);
}
export function addOnSpeechCancelledListener(
listener: () => void
): Subscription {
return emitter.addListener<void>(ReactEvents.onSpeechCancelled, listener);
}
export function addOnSpeechResultListener(
listener: (event: OnSpeechResultEventPayload) => void
): Subscription {
return emitter.addListener<OnSpeechResultEventPayload>(
ReactEvents.onSpeechResult,
listener
);
}
export function addOnSpeechErrorListener(
listener: (event: OnSpeechErrorEventPayload) => void
): Subscription {
return emitter.addListener<OnSpeechErrorEventPayload>(
ReactEvents.onSpeechError,
listener
);
}
export { OnSpeechResultEventPayload, OnSpeechErrorEventPayload, ReactEvents };