capacitor-microphone 0.0.9 → 0.0.10

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.
@@ -141,36 +141,38 @@ private Intent speechIntent;
141
141
 
142
142
  @Override
143
143
  public void onError(int error) {
144
+ if (error == SpeechRecognizer.ERROR_NO_MATCH ||
145
+ error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT) {
146
+ speechRecognizer.startListening(speechIntent);
147
+ return;
148
+ }
149
+
144
150
  if (currentCall != null) {
145
151
  currentCall.reject(mapError(error));
146
152
  currentCall = null;
147
153
  }
154
+
148
155
  stopSpeech();
149
156
  }
150
157
 
158
+
151
159
  @Override
152
160
  public void onResults(Bundle results) {
153
161
  ArrayList<String> matches =
154
- results.getStringArrayList(
155
- SpeechRecognizer.RESULTS_RECOGNITION);
162
+ results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
156
163
 
157
- if (matches != null && matches.size() > 0) {
164
+ if (matches != null && !matches.isEmpty()) {
158
165
  String text = matches.get(0);
159
166
 
160
167
  notifyListeners("partialResult", new JSObject()
161
168
  .put("text", text)
162
169
  .put("isFinal", true));
163
-
164
- if (currentCall != null) {
165
- currentCall.resolve(new JSObject()
166
- .put("text", text)
167
- .put("isFinal", true));
168
- currentCall = null;
169
- }
170
170
  }
171
- stopSpeech();
171
+
172
+ speechRecognizer.startListening(speechIntent);
172
173
  }
173
174
 
175
+
174
176
  @Override
175
177
  public void onPartialResults(Bundle partialResults) {
176
178
  ArrayList<String> matches =
@@ -213,8 +215,9 @@ private Intent speechIntent;
213
215
 
214
216
  @PluginMethod
215
217
  public void stopListening(PluginCall call) {
218
+ currentCall = null;
216
219
  stopSpeech();
217
- call.resolve(new JSObject().put("stopped", true));
220
+ call.resolve();
218
221
  }
219
222
 
220
223
  private void stopSpeech() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-microphone",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "plugin to use the microphone",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",