apps-sdk 1.0.130 → 1.0.132
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/libraries/Voice.js +27 -5
package/package.json
CHANGED
package/src/libraries/Voice.js
CHANGED
|
@@ -1,25 +1,46 @@
|
|
|
1
1
|
import Voice from '@react-native-voice/voice';
|
|
2
2
|
import Session from "./Session";
|
|
3
3
|
|
|
4
|
-
class
|
|
4
|
+
class VoiceService {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.voice = Voice;
|
|
7
|
+
this.inactivityTimeout = null;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
async startRecognizing(onSpeechStart, onSpeechRecognized, onSpeechResults) {
|
|
10
|
+
async startRecognizing(onSpeechStart, onSpeechRecognized, onSpeechResults, inactivitySeconds = 3) {
|
|
10
11
|
try {
|
|
11
12
|
const language = Session.getDeviceLanguageAndRegion();
|
|
12
|
-
|
|
13
|
+
|
|
14
|
+
this.voice.onSpeechStart = () => {
|
|
15
|
+
onSpeechStart();
|
|
16
|
+
this.resetInactivityTimeout(inactivitySeconds);
|
|
17
|
+
};
|
|
18
|
+
|
|
13
19
|
this.voice.onSpeechRecognized = onSpeechRecognized;
|
|
14
|
-
|
|
20
|
+
|
|
21
|
+
this.voice.onSpeechResults = (e) => {
|
|
22
|
+
onSpeechResults(e.value);
|
|
23
|
+
this.resetInactivityTimeout(inactivitySeconds);
|
|
24
|
+
};
|
|
25
|
+
|
|
15
26
|
await this.voice.start(language);
|
|
16
27
|
} catch (e) {
|
|
17
28
|
console.error(e);
|
|
18
29
|
}
|
|
19
30
|
}
|
|
20
31
|
|
|
32
|
+
resetInactivityTimeout(seconds) {
|
|
33
|
+
if (this.inactivityTimeout) {
|
|
34
|
+
clearTimeout(this.inactivityTimeout);
|
|
35
|
+
}
|
|
36
|
+
this.inactivityTimeout = setTimeout(() => {
|
|
37
|
+
this.stopRecognizing();
|
|
38
|
+
}, seconds * 1000);
|
|
39
|
+
}
|
|
40
|
+
|
|
21
41
|
async stopRecognizing() {
|
|
22
42
|
try {
|
|
43
|
+
clearTimeout(this.inactivityTimeout);
|
|
23
44
|
await this.voice.stop();
|
|
24
45
|
} catch (e) {
|
|
25
46
|
console.error(e);
|
|
@@ -28,6 +49,7 @@ class Voice {
|
|
|
28
49
|
|
|
29
50
|
async destroyVoice() {
|
|
30
51
|
try {
|
|
52
|
+
clearTimeout(this.inactivityTimeout);
|
|
31
53
|
await this.voice.destroy();
|
|
32
54
|
} catch (e) {
|
|
33
55
|
console.error(e);
|
|
@@ -35,4 +57,4 @@ class Voice {
|
|
|
35
57
|
}
|
|
36
58
|
}
|
|
37
59
|
|
|
38
|
-
export default new
|
|
60
|
+
export default new VoiceService();
|