apps-sdk 1.1.86 → 1.1.88

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.1.86",
3
+ "version": "1.1.88",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "author": "ASD",
@@ -17,6 +17,7 @@
17
17
  "expo-notifications": ">=0.29.0",
18
18
  "expo-sharing": ">=13.0.0",
19
19
  "expo-speech": ">=13.0.0",
20
+ "expo-speech-recognition": ">=0.1.0",
20
21
  "expo-store-review": ">=8.0.0",
21
22
  "expo-tracking-transparency": ">=5.1.0",
22
23
  "react-native": ">=0.76.0 <0.81.0",
@@ -32,7 +33,7 @@
32
33
  "@expo/config-plugins": "~9.0.0",
33
34
  "@react-native-async-storage/async-storage": "1.23.1",
34
35
  "@react-native-community/netinfo": "11.4.1",
35
- "@react-native-voice/voice": "^3.2.4",
36
+ "expo-speech-recognition": "^3.0.1",
36
37
  "franc-min": "^6.2.0",
37
38
  "mixpanel-react-native": "^3.1.3",
38
39
  "react-native-btr": "^2.2.1",
@@ -1,34 +1,59 @@
1
1
  import * as config from '../../config';
2
- import Voice from '@react-native-voice/voice';
2
+ import { ExpoSpeechRecognitionModule } from 'expo-speech-recognition';
3
3
  import Session from "./Session";
4
4
  import * as Speech from 'expo-speech';
5
5
  import { franc } from 'franc-min';
6
6
 
7
7
  class VoiceService {
8
8
  constructor() {
9
- this.voice = Voice;
10
9
  this.inactivityTimeout = null;
10
+ this.resultListener = null;
11
+ this.isRecognizing = false;
11
12
  }
12
13
 
13
14
  async startRecognizing(onSpeechStart, onSpeechRecognized, onSpeechResults, onInactivityTimeout, inactivitySeconds = 3) {
14
15
  try {
15
- const language = Session.getDeviceLanguageAndRegion();
16
+ const { status } = await ExpoSpeechRecognitionModule.requestPermissionsAsync();
17
+ if (status !== 'granted') {
18
+ throw new Error('Speech recognition permission not granted');
19
+ }
20
+
21
+ let language = Session.getDeviceLanguageAndRegion();
22
+ language = this.normalizeLocale(language);
16
23
 
17
- this.voice.onSpeechStart = () => {
24
+ if (this.resultListener) {
25
+ this.resultListener.remove();
26
+ }
27
+
28
+ ExpoSpeechRecognitionModule.addListener('start', () => {
18
29
  onSpeechStart();
19
30
  this.resetInactivityTimeout(inactivitySeconds, onInactivityTimeout);
20
- };
31
+ });
21
32
 
22
- this.voice.onSpeechRecognized = onSpeechRecognized;
33
+ this.resultListener = ExpoSpeechRecognitionModule.addListener('result', (event) => {
34
+ if (event.results && event.results.length > 0) {
35
+ const results = event.results.map(r => r.transcript);
36
+ onSpeechResults(results);
37
+ this.resetInactivityTimeout(inactivitySeconds, onInactivityTimeout);
38
+ }
39
+ });
23
40
 
24
- this.voice.onSpeechResults = (e) => {
25
- onSpeechResults(e.value);
26
- this.resetInactivityTimeout(inactivitySeconds, onInactivityTimeout);
27
- };
41
+ ExpoSpeechRecognitionModule.addListener('error', (event) => {
42
+ console.error('Speech recognition error:', event.error, event.message);
43
+ });
44
+
45
+ await ExpoSpeechRecognitionModule.start({
46
+ lang: language,
47
+ interimResults: true,
48
+ maxAlternatives: 1,
49
+ continuous: true,
50
+ });
51
+
52
+ this.isRecognizing = true;
28
53
 
29
- await this.voice.start(language);
30
54
  } catch (e) {
31
- console.error(e);
55
+ console.error('Speech recognition error:', e);
56
+ this.isRecognizing = false;
32
57
  }
33
58
  }
34
59
 
@@ -46,20 +71,79 @@ class VoiceService {
46
71
 
47
72
  async stopRecognizing() {
48
73
  try {
49
- clearTimeout(this.inactivityTimeout);
50
- await this.voice.stop();
74
+ if (this.inactivityTimeout) {
75
+ clearTimeout(this.inactivityTimeout);
76
+ }
77
+ if (this.resultListener) {
78
+ this.resultListener.remove();
79
+ this.resultListener = null;
80
+ }
81
+ if (this.isRecognizing) {
82
+ await ExpoSpeechRecognitionModule.stop();
83
+ this.isRecognizing = false;
84
+ }
51
85
  } catch (e) {
52
- console.error(e);
86
+ console.error('Stop recognition error:', e);
53
87
  }
54
88
  }
55
89
 
56
90
  async destroyVoice() {
57
91
  try {
58
- clearTimeout(this.inactivityTimeout);
59
- await this.voice.destroy();
92
+ await this.stopRecognizing();
60
93
  } catch (e) {
61
- console.error(e);
94
+ console.error('Destroy voice error:', e);
95
+ }
96
+ }
97
+
98
+ normalizeLocale(locale) {
99
+ const [lang, region] = locale.split('-');
100
+
101
+ const validCombinations = {
102
+ 'en': ['US', 'GB', 'AU', 'CA', 'NZ', 'ZA', 'AE', 'IN', 'SG', 'IE', 'PH', 'SA', 'ID'],
103
+ 'es': ['ES', 'MX', 'CL', 'CO', '419', 'US'],
104
+ 'fr': ['FR', 'CA', 'BE', 'CH'],
105
+ 'de': ['DE', 'AT', 'CH'],
106
+ 'pt': ['PT', 'BR'],
107
+ 'it': ['IT', 'CH'],
108
+ 'nl': ['NL', 'BE'],
109
+ 'zh': ['CN', 'TW', 'HK'],
110
+ 'ar': ['SA'],
111
+ 'ja': ['JP'],
112
+ 'ko': ['KR'],
113
+ 'ru': ['RU'],
114
+ 'tr': ['TR'],
115
+ 'vi': ['VN'],
116
+ 'sv': ['SE'],
117
+ 'ms': ['MY'],
118
+ 'id': ['ID'],
119
+ 'el': ['GR'],
120
+ 'uk': ['UA'],
121
+ 'cs': ['CZ'],
122
+ 'pl': ['PL'],
123
+ 'hi': ['IN'],
124
+ 'hr': ['HR'],
125
+ 'ca': ['ES'],
126
+ 'th': ['TH'],
127
+ 'da': ['DK'],
128
+ 'fi': ['FI'],
129
+ 'he': ['IL'],
130
+ 'nb': ['NO'],
131
+ 'sk': ['SK'],
132
+ 'ro': ['RO'],
133
+ 'hu': ['HU'],
134
+ };
135
+
136
+ if (!validCombinations[lang]) {
137
+ return 'en-US';
62
138
  }
139
+
140
+ const validRegions = validCombinations[lang];
141
+
142
+ if (validRegions.includes(region)) {
143
+ return locale;
144
+ }
145
+
146
+ return `${lang}-${validRegions[0]}`;
63
147
  }
64
148
 
65
149
  speak(message, language = null, voice = null, onStart, onDone, onError) {