apps-sdk 1.1.87 → 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 +1 -1
- package/src/libraries/Voice.js +65 -9
package/package.json
CHANGED
package/src/libraries/Voice.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as config from '../../config';
|
|
2
|
-
import { ExpoSpeechRecognitionModule
|
|
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';
|
|
@@ -18,33 +18,38 @@ class VoiceService {
|
|
|
18
18
|
throw new Error('Speech recognition permission not granted');
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
let language = Session.getDeviceLanguageAndRegion();
|
|
22
|
+
language = this.normalizeLocale(language);
|
|
22
23
|
|
|
23
24
|
if (this.resultListener) {
|
|
24
25
|
this.resultListener.remove();
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
ExpoSpeechRecognitionModule.addListener('start', () => {
|
|
29
|
+
onSpeechStart();
|
|
30
|
+
this.resetInactivityTimeout(inactivitySeconds, onInactivityTimeout);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
this.resultListener = ExpoSpeechRecognitionModule.addListener('result', (event) => {
|
|
28
34
|
if (event.results && event.results.length > 0) {
|
|
29
35
|
const results = event.results.map(r => r.transcript);
|
|
30
36
|
onSpeechResults(results);
|
|
31
37
|
this.resetInactivityTimeout(inactivitySeconds, onInactivityTimeout);
|
|
32
38
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
ExpoSpeechRecognitionModule.addListener('error', (event) => {
|
|
42
|
+
console.error('Speech recognition error:', event.error, event.message);
|
|
36
43
|
});
|
|
37
44
|
|
|
38
45
|
await ExpoSpeechRecognitionModule.start({
|
|
39
46
|
lang: language,
|
|
40
47
|
interimResults: true,
|
|
41
48
|
maxAlternatives: 1,
|
|
42
|
-
continuous:
|
|
49
|
+
continuous: true,
|
|
43
50
|
});
|
|
44
51
|
|
|
45
52
|
this.isRecognizing = true;
|
|
46
|
-
onSpeechStart();
|
|
47
|
-
this.resetInactivityTimeout(inactivitySeconds, onInactivityTimeout);
|
|
48
53
|
|
|
49
54
|
} catch (e) {
|
|
50
55
|
console.error('Speech recognition error:', e);
|
|
@@ -90,6 +95,57 @@ class VoiceService {
|
|
|
90
95
|
}
|
|
91
96
|
}
|
|
92
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';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const validRegions = validCombinations[lang];
|
|
141
|
+
|
|
142
|
+
if (validRegions.includes(region)) {
|
|
143
|
+
return locale;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return `${lang}-${validRegions[0]}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
93
149
|
speak(message, language = null, voice = null, onStart, onDone, onError) {
|
|
94
150
|
let detectedLanguageCode = 'en_US';
|
|
95
151
|
try {
|