forked from ak1394/react-native-tts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
72 lines (56 loc) · 1.42 KB
/
index.js
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
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
const TextToSpeech = NativeModules.TextToSpeech;
class Tts extends NativeEventEmitter {
constructor() {
super(TextToSpeech);
}
setDucking(enabled) {
return TextToSpeech.setDucking(enabled);
}
setDefaultVoice(voiceId) {
return TextToSpeech.setDefaultVoice(voiceId);
}
setDefaultRate(rate, skipTransform) {
return TextToSpeech.setDefaultRate(rate, !!skipTransform);
}
setDefaultPitch(pitch) {
return TextToSpeech.setDefaultPitch(pitch);
}
setDefaultLanguage(language) {
return TextToSpeech.setDefaultLanguage(language);
}
voices() {
return TextToSpeech.voices();
}
speak(utterance, voiceId) {
if(Platform.OS === 'ios') {
return TextToSpeech.speak(utterance, voiceId);
} else {
return TextToSpeech.speak(utterance)
}
}
stop(onWordBoundary) {
if(Platform.OS === 'ios') {
return TextToSpeech.stop(onWordBoundary);
} else {
return TextToSpeech.stop();
}
}
pause(onWordBoundary) {
if(Platform.OS === 'ios') {
return TextToSpeech.pause(onWordBoundary);
}
}
resume() {
if(Platform.OS === 'ios') {
return TextToSpeech.resume();
}
}
addEventListener(type, handler) {
this.addListener(type, handler);
}
removeEventListener(type, handler) {
this.removeListener(type, handler);
}
}
export default new Tts();