capacitor-microphone 0.1.16 → 0.1.17

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,6 +40,8 @@ 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 restartScheduled = false;
44
+
43
45
 
44
46
 
45
47
  @PluginMethod
@@ -149,6 +151,22 @@ public void startListening(PluginCall call) {
149
151
  startListeningInternal(call, lang);
150
152
  }
151
153
 
154
+ private void safeRestartListening() {
155
+ if (restartScheduled) return;
156
+ restartScheduled = true;
157
+
158
+ getActivity()
159
+ .getWindow()
160
+ .getDecorView()
161
+ .postDelayed(() -> {
162
+ restartScheduled = false;
163
+ if (!isDestroyed && isListening && speechRecognizer != null) {
164
+ speechRecognizer.startListening(speechIntent);
165
+ }
166
+ }, 350);
167
+ }
168
+
169
+
152
170
 
153
171
  private void startListeningInternal(PluginCall call, String lang) {
154
172
  isDestroyed = false;
@@ -187,10 +205,7 @@ private void startListeningInternal(PluginCall call, String lang) {
187
205
 
188
206
  if (error == SpeechRecognizer.ERROR_NO_MATCH ||
189
207
  error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT) {
190
-
191
- if (!isDestroyed && isListening && speechRecognizer != null) {
192
- speechRecognizer.startListening(speechIntent);
193
- }
208
+ safeRestartListening();
194
209
  return;
195
210
  }
196
211
 
@@ -215,7 +230,7 @@ private void startListeningInternal(PluginCall call, String lang) {
215
230
  }
216
231
 
217
232
  if (!isDestroyed && isListening && speechRecognizer != null) {
218
- speechRecognizer.startListening(speechIntent);
233
+ safeRestartListening();
219
234
  }
220
235
  }
221
236
 
@@ -250,6 +265,14 @@ private void startListeningInternal(PluginCall call, String lang) {
250
265
  RecognizerIntent.EXTRA_LANGUAGE, lang);
251
266
  speechIntent.putExtra(
252
267
  RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
268
+ speechIntent.putExtra(
269
+ RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
270
+ 1500
271
+ );
272
+ speechIntent.putExtra(
273
+ RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
274
+ 1500
275
+ );
253
276
 
254
277
 
255
278
  speechRecognizer.startListening(speechIntent);
@@ -399,7 +422,7 @@ private void startListeningInternal(PluginCall call, String lang) {
399
422
  if (error == SpeechRecognizer.ERROR_NO_MATCH ||
400
423
  error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT) {
401
424
  if (!isDestroyed && isListening && speechRecognizer != null) {
402
- speechRecognizer.startListening(speechIntent);
425
+ safeRestartListening();
403
426
  }
404
427
  return;
405
428
  }
@@ -423,9 +446,7 @@ private void startListeningInternal(PluginCall call, String lang) {
423
446
  );
424
447
  }
425
448
 
426
- if (!isDestroyed && isListening && speechRecognizer != null) {
427
- speechRecognizer.startListening(speechIntent);
428
- }
449
+ safeRestartListening();
429
450
  }
430
451
 
431
452
  @Override
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-microphone",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "plugin to use the microphone",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",