capacitor-microphone 0.0.21 → 0.0.22

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.
@@ -40,7 +40,7 @@ private boolean isDestroyed = false;
40
40
  private long lastStopTime = 0;
41
41
  private static final long RESTART_COOLDOWN_MS = 400;
42
42
  private Runnable delayedStartRunnable;
43
- private boolean ignoreNextResult = false;
43
+ private int ignoreResultCount = 0;
44
44
 
45
45
 
46
46
  @PluginMethod
@@ -152,6 +152,7 @@ public void startListening(PluginCall call) {
152
152
 
153
153
 
154
154
  private void startListeningInternal(PluginCall call, String lang) {
155
+ ignoreResultCount = 0;
155
156
  isDestroyed = false;
156
157
  isListening = true;
157
158
 
@@ -211,16 +212,16 @@ private void startListeningInternal(PluginCall call, String lang) {
211
212
  @Override
212
213
  public void onResults(Bundle results) {
213
214
 
214
- if (ignoreNextResult) {
215
- ignoreNextResult = false;
216
- return;
217
- }
218
-
215
+ if (ignoreResultCount > 0) {
216
+ ignoreResultCount--;
217
+ return;
218
+ }
219
+
220
+
219
221
  if (!isListening) return;
220
222
 
221
223
  ArrayList<String> matches =
222
- results.getStringArrayList(
223
- SpeechRecognizer.RESULTS_RECOGNITION);
224
+ results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
224
225
 
225
226
  if (matches != null && !matches.isEmpty()) {
226
227
  notifyListeners(
@@ -230,21 +231,18 @@ private void startListeningInternal(PluginCall call, String lang) {
230
231
  .put("isFinal", true)
231
232
  );
232
233
  }
233
-
234
- if (!isDestroyed && isListening && speechRecognizer != null && speechIntent != null) {
235
- speechRecognizer.startListening(speechIntent);
236
- }
237
-
238
234
  }
239
235
 
236
+
240
237
  @Override
241
238
  public void onPartialResults(Bundle partialResults) {
242
239
 
243
- if (ignoreNextResult) {
244
- ignoreNextResult = false;
240
+ if (ignoreResultCount > 0) {
241
+ ignoreResultCount--;
245
242
  return;
246
243
  }
247
244
 
245
+
248
246
  if (!isListening || isDestroyed) return;
249
247
 
250
248
  ArrayList<String> matches =
@@ -335,7 +333,7 @@ public void restartListening(PluginCall call) {
335
333
  }
336
334
 
337
335
  stopSpeech();
338
- ignoreNextResult = true;
336
+ ignoreResultCount = 3;
339
337
  getActivity().runOnUiThread(() -> {
340
338
  getActivity()
341
339
  .getWindow()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-microphone",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "plugin to use the microphone",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",