-
Notifications
You must be signed in to change notification settings - Fork 160
/
index.d.ts
118 lines (106 loc) · 3.55 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import * as RN from "react-native";
type SimpleEvents = "tts-start" | "tts-finish" | "tts-error" | "tts-cancel";
type SimpleEvent = {
utteranceId: string | number;
};
type ProgressEventName = "tts-progress";
type ProgressEvent = {
utteranceId: string | number;
location: number;
length: number;
};
export type TtsEvents = SimpleEvents | ProgressEventName;
export type TtsEvent<
T extends TtsEvents = TtsEvents
> = T extends ProgressEventName ? ProgressEvent : SimpleEvent;
export type TtsEventHandler<T extends TtsEvents = TtsEvents> = (
event: TtsEvent<T>
) => any;
export type TtsError = {
code:
| "no_engine"
| "error"
| "not_ready"
| "invalid_request"
| "network_error"
| "network_timeout"
| "not_installed_yet"
| "output_error"
| "service_error"
| "synthesis_error"
| "lang_missing_data"
| "lang_not_supported"
| "Android AudioManager error"
| "not_available"
| "not_found"
| "bad_rate";
message: string;
};
export type IOSSilentSwitchBehavior = "inherit" | "ignore" | "obey"
export type Voice = {
id: string;
name: string;
language: string;
quality: number;
latency: number;
networkConnectionRequired: boolean;
notInstalled: boolean;
};
export type Engine = {
name: string;
label: string;
default: boolean;
icon: number;
};
export type AndroidOptions = {
/** Parameter key to specify the audio stream type to be used when speaking text or playing back a file */
KEY_PARAM_STREAM:
| "STREAM_VOICE_CALL"
| "STREAM_SYSTEM"
| "STREAM_RING"
| "STREAM_MUSIC"
| "STREAM_ALARM"
| "STREAM_NOTIFICATION"
| "STREAM_DTMF"
| "STREAM_ACCESSIBILITY";
/** Parameter key to specify the speech volume relative to the current stream type volume used when speaking text. Volume is specified as a float ranging from 0 to 1 where 0 is silence, and 1 is the maximum volume (the default behavior). */
KEY_PARAM_VOLUME: number;
/** Parameter key to specify how the speech is panned from left to right when speaking text. Pan is specified as a float ranging from -1 to +1 where -1 maps to a hard-left pan, 0 to center (the default behavior), and +1 to hard-right. */
KEY_PARAM_PAN: number;
};
export type Options =
| string
| {
iosVoiceId: string;
rate: number;
androidParams: AndroidOptions;
};
export class ReactNativeTts extends RN.NativeEventEmitter {
getInitStatus: () => Promise<"success">;
requestInstallEngine: () => Promise<"success">;
requestInstallData: () => Promise<"success">;
setDucking: (enabled: boolean) => Promise<"success">;
setDefaultEngine: (engineName: string) => Promise<boolean>;
setDefaultVoice: (voiceId: string) => Promise<"success">;
setDefaultRate: (rate: number, skipTransform?: boolean) => Promise<"success">;
setDefaultPitch: (pitch: number) => Promise<"success">;
setDefaultLanguage: (language: string) => Promise<"success">;
setIgnoreSilentSwitch: (ignoreSilentSwitch: IOSSilentSwitchBehavior) => Promise<boolean>;
voices: () => Promise<Voice[]>;
engines: () => Promise<Engine[]>;
/** Read the sentence and return an id for the task. */
speak: (utterance: string, options?: Options) => string | number;
stop: (onWordBoundary?: boolean) => Promise<boolean>;
pause: (onWordBoundary?: boolean) => Promise<boolean>;
resume: () => Promise<boolean>;
addEventListener: <T extends TtsEvents>(
type: T,
handler: TtsEventHandler<T>
) => void;
removeEventListener: <T extends TtsEvents>(
type: T,
handler: TtsEventHandler<T>
) => void;
}
declare const Tts: ReactNativeTts;
export default Tts;