capacitor-microphone 0.0.11 → 0.0.12
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.
|
@@ -36,6 +36,7 @@ private SpeechRecognizer speechRecognizer;
|
|
|
36
36
|
private PluginCall currentCall;
|
|
37
37
|
private Intent speechIntent;
|
|
38
38
|
private boolean isListening = false;
|
|
39
|
+
private boolean isDestroyed = false;
|
|
39
40
|
|
|
40
41
|
|
|
41
42
|
@PluginMethod
|
|
@@ -109,6 +110,8 @@ private boolean isListening = false;
|
|
|
109
110
|
@PluginMethod
|
|
110
111
|
public void startListening(PluginCall call) {
|
|
111
112
|
|
|
113
|
+
|
|
114
|
+
|
|
112
115
|
if (getPermissionState("microphone") != PermissionState.GRANTED) {
|
|
113
116
|
call.reject("Microphone permission not granted");
|
|
114
117
|
return;
|
|
@@ -126,6 +129,7 @@ private boolean isListening = false;
|
|
|
126
129
|
|
|
127
130
|
this.currentCall = call;
|
|
128
131
|
isListening = true;
|
|
132
|
+
isDestroyed = false;
|
|
129
133
|
|
|
130
134
|
String lang = call.getString("lang", "es-MX");
|
|
131
135
|
|
|
@@ -143,12 +147,12 @@ private boolean isListening = false;
|
|
|
143
147
|
|
|
144
148
|
@Override
|
|
145
149
|
public void onError(int error) {
|
|
146
|
-
if (!isListening) return;
|
|
150
|
+
if (isDestroyed || !isListening) return;
|
|
147
151
|
|
|
148
152
|
if (error == SpeechRecognizer.ERROR_NO_MATCH ||
|
|
149
153
|
error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT) {
|
|
150
154
|
|
|
151
|
-
if (isListening) {
|
|
155
|
+
if (!isDestroyed && isListening && speechRecognizer != null) {
|
|
152
156
|
speechRecognizer.startListening(speechIntent);
|
|
153
157
|
}
|
|
154
158
|
return;
|
|
@@ -159,6 +163,7 @@ private boolean isListening = false;
|
|
|
159
163
|
|
|
160
164
|
|
|
161
165
|
|
|
166
|
+
|
|
162
167
|
@Override
|
|
163
168
|
public void onResults(Bundle results) {
|
|
164
169
|
if (!isListening) return;
|
|
@@ -172,7 +177,7 @@ private boolean isListening = false;
|
|
|
172
177
|
.put("isFinal", true));
|
|
173
178
|
}
|
|
174
179
|
|
|
175
|
-
if (isListening) {
|
|
180
|
+
if (!isDestroyed && isListening && speechRecognizer != null) {
|
|
176
181
|
speechRecognizer.startListening(speechIntent);
|
|
177
182
|
}
|
|
178
183
|
}
|
|
@@ -217,21 +222,11 @@ private boolean isListening = false;
|
|
|
217
222
|
}
|
|
218
223
|
|
|
219
224
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
@PluginMethod
|
|
223
|
-
public void stopListening(PluginCall call) {
|
|
224
|
-
isListening = false;
|
|
225
|
-
currentCall = null;
|
|
226
|
-
stopSpeech();
|
|
227
|
-
call.resolve();
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
225
|
private void stopSpeech() {
|
|
232
226
|
try {
|
|
233
227
|
if (speechRecognizer != null) {
|
|
234
228
|
speechRecognizer.cancel();
|
|
229
|
+
speechRecognizer.setRecognitionListener(null);
|
|
235
230
|
speechRecognizer.destroy();
|
|
236
231
|
speechRecognizer = null;
|
|
237
232
|
}
|
|
@@ -240,13 +235,24 @@ private boolean isListening = false;
|
|
|
240
235
|
|
|
241
236
|
|
|
242
237
|
|
|
238
|
+
@PluginMethod
|
|
239
|
+
public void stopListening(PluginCall call) {
|
|
240
|
+
isListening = false;
|
|
241
|
+
isDestroyed = true;
|
|
242
|
+
currentCall = null;
|
|
243
|
+
stopSpeech();
|
|
244
|
+
call.resolve();
|
|
245
|
+
}
|
|
246
|
+
|
|
243
247
|
@Override
|
|
244
248
|
protected void handleOnDestroy() {
|
|
249
|
+
isDestroyed = true;
|
|
245
250
|
isListening = false;
|
|
246
251
|
stopSpeech();
|
|
247
252
|
}
|
|
248
253
|
|
|
249
254
|
|
|
255
|
+
|
|
250
256
|
private String mapError(int error) {
|
|
251
257
|
switch (error) {
|
|
252
258
|
case SpeechRecognizer.ERROR_AUDIO: return "Audio error";
|