apps-sdk 1.1.86 → 1.1.87

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.87",
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,54 @@
1
1
  import * as config from '../../config';
2
- import Voice from '@react-native-voice/voice';
2
+ import { ExpoSpeechRecognitionModule, addSpeechRecognitionEventListener } 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 {
16
+ const { status } = await ExpoSpeechRecognitionModule.requestPermissionsAsync();
17
+ if (status !== 'granted') {
18
+ throw new Error('Speech recognition permission not granted');
19
+ }
20
+
15
21
  const language = Session.getDeviceLanguageAndRegion();
16
22
 
17
- this.voice.onSpeechStart = () => {
18
- onSpeechStart();
19
- this.resetInactivityTimeout(inactivitySeconds, onInactivityTimeout);
20
- };
23
+ if (this.resultListener) {
24
+ this.resultListener.remove();
25
+ }
21
26
 
22
- this.voice.onSpeechRecognized = onSpeechRecognized;
27
+ this.resultListener = addSpeechRecognitionEventListener('result', (event) => {
28
+ if (event.results && event.results.length > 0) {
29
+ const results = event.results.map(r => r.transcript);
30
+ onSpeechResults(results);
31
+ this.resetInactivityTimeout(inactivitySeconds, onInactivityTimeout);
32
+ }
33
+ if (event.isFinal) {
34
+ this.stopRecognizing();
35
+ }
36
+ });
23
37
 
24
- this.voice.onSpeechResults = (e) => {
25
- onSpeechResults(e.value);
26
- this.resetInactivityTimeout(inactivitySeconds, onInactivityTimeout);
27
- };
38
+ await ExpoSpeechRecognitionModule.start({
39
+ lang: language,
40
+ interimResults: true,
41
+ maxAlternatives: 1,
42
+ continuous: false,
43
+ });
44
+
45
+ this.isRecognizing = true;
46
+ onSpeechStart();
47
+ this.resetInactivityTimeout(inactivitySeconds, onInactivityTimeout);
28
48
 
29
- await this.voice.start(language);
30
49
  } catch (e) {
31
- console.error(e);
50
+ console.error('Speech recognition error:', e);
51
+ this.isRecognizing = false;
32
52
  }
33
53
  }
34
54
 
@@ -46,19 +66,27 @@ class VoiceService {
46
66
 
47
67
  async stopRecognizing() {
48
68
  try {
49
- clearTimeout(this.inactivityTimeout);
50
- await this.voice.stop();
69
+ if (this.inactivityTimeout) {
70
+ clearTimeout(this.inactivityTimeout);
71
+ }
72
+ if (this.resultListener) {
73
+ this.resultListener.remove();
74
+ this.resultListener = null;
75
+ }
76
+ if (this.isRecognizing) {
77
+ await ExpoSpeechRecognitionModule.stop();
78
+ this.isRecognizing = false;
79
+ }
51
80
  } catch (e) {
52
- console.error(e);
81
+ console.error('Stop recognition error:', e);
53
82
  }
54
83
  }
55
84
 
56
85
  async destroyVoice() {
57
86
  try {
58
- clearTimeout(this.inactivityTimeout);
59
- await this.voice.destroy();
87
+ await this.stopRecognizing();
60
88
  } catch (e) {
61
- console.error(e);
89
+ console.error('Destroy voice error:', e);
62
90
  }
63
91
  }
64
92