apps-sdk 1.0.134 → 1.0.136

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.0.134",
3
+ "version": "1.0.136",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,6 +23,7 @@
23
23
  "expo-media-library": "~15.9.2",
24
24
  "expo-notifications": "~0.27.8",
25
25
  "expo-sharing": "^11.10.0",
26
+ "expo-speech": "^13.0.0",
26
27
  "expo-store-review": "~6.8.3",
27
28
  "expo-tracking-transparency": "~3.3.0",
28
29
  "react-native": "0.73.6",
@@ -1,5 +1,6 @@
1
1
  import Voice from '@react-native-voice/voice';
2
2
  import Session from "./Session";
3
+ import * as Speech from 'expo-speech';
3
4
 
4
5
  class VoiceService {
5
6
  constructor() {
@@ -7,20 +8,20 @@ class VoiceService {
7
8
  this.inactivityTimeout = null;
8
9
  }
9
10
 
10
- async startRecognizing(onSpeechStart, onSpeechRecognized, onSpeechResults, inactivitySeconds = 3) {
11
+ async startRecognizing(onSpeechStart, onSpeechRecognized, onSpeechResults, onInactivityTimeout, inactivitySeconds = 3) {
11
12
  try {
12
13
  const language = Session.getDeviceLanguageAndRegion();
13
14
 
14
15
  this.voice.onSpeechStart = () => {
15
16
  onSpeechStart();
16
- this.resetInactivityTimeout(inactivitySeconds);
17
+ this.resetInactivityTimeout(inactivitySeconds, onInactivityTimeout);
17
18
  };
18
19
 
19
20
  this.voice.onSpeechRecognized = onSpeechRecognized;
20
21
 
21
22
  this.voice.onSpeechResults = (e) => {
22
23
  onSpeechResults(e.value);
23
- this.resetInactivityTimeout(inactivitySeconds);
24
+ this.resetInactivityTimeout(inactivitySeconds, onInactivityTimeout);
24
25
  };
25
26
 
26
27
  await this.voice.start(language);
@@ -29,12 +30,15 @@ class VoiceService {
29
30
  }
30
31
  }
31
32
 
32
- resetInactivityTimeout(seconds) {
33
+ resetInactivityTimeout(seconds, onInactivityTimeout) {
33
34
  if (this.inactivityTimeout) {
34
35
  clearTimeout(this.inactivityTimeout);
35
36
  }
36
37
  this.inactivityTimeout = setTimeout(() => {
37
38
  this.stopRecognizing();
39
+ if (onInactivityTimeout) {
40
+ onInactivityTimeout();
41
+ }
38
42
  }, seconds * 1000);
39
43
  }
40
44
 
@@ -55,6 +59,29 @@ class VoiceService {
55
59
  console.error(e);
56
60
  }
57
61
  }
62
+
63
+ speak(message, language = null, voice = null, onStart, onDone, onError) {
64
+ const deviceLanguage = Session.getDeviceLanguageAndRegion();
65
+
66
+ const finalLanguage = language || deviceLanguage;
67
+ const finalVoice = voice || `${deviceLanguage}-language`;
68
+
69
+ Speech.speak(message, {
70
+ language: finalLanguage,
71
+ voice: finalVoice,
72
+ rate: 1,
73
+ pitch: 1,
74
+ onStart: () => {
75
+ if (onStart) onStart();
76
+ },
77
+ onDone: () => {
78
+ if (onDone) onDone();
79
+ },
80
+ onError: (error) => {
81
+ if (onError) onError(error);
82
+ }
83
+ });
84
+ }
58
85
  }
59
86
 
60
87
  export default new VoiceService();
package/types/index.d.ts CHANGED
@@ -130,10 +130,20 @@ declare module 'apps-sdk' {
130
130
  onSpeechStart: () => void,
131
131
  onSpeechRecognized: () => void,
132
132
  onSpeechResults: (results: string[]) => void,
133
- inactivitySeconds?: number
133
+ onInactivityTimeout: () => void,
134
+ inactivitySeconds?: number,
134
135
  ): Promise<void>;
136
+
135
137
  stopRecognizing(): Promise<void>;
136
138
  destroyVoice(): Promise<void>;
139
+ speak(
140
+ message: string,
141
+ language?: string | null,
142
+ voice?: string | null,
143
+ onStart?: () => void,
144
+ onDone?: () => void,
145
+ onError?: (error: any) => void
146
+ ): void;
137
147
  }
138
148
 
139
149
  export interface PayWallProps {