@capgo/capacitor-speech-recognition 7.0.1 → 7.1.0

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.
@@ -11,6 +11,7 @@ import com.getcapacitor.PluginCall;
11
11
  import java.util.List;
12
12
 
13
13
  public class Receiver extends BroadcastReceiver implements Constants {
14
+
14
15
  private List<String> supportedLanguagesList;
15
16
  private String languagePref;
16
17
  private final PluginCall call;
@@ -63,11 +63,13 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
63
63
  @PluginMethod
64
64
  public void start(PluginCall call) {
65
65
  if (!SpeechRecognizer.isRecognitionAvailable(bridge.getContext())) {
66
+ Logger.warn(TAG, "start() called but speech recognizer unavailable");
66
67
  call.unavailable(NOT_AVAILABLE);
67
68
  return;
68
69
  }
69
70
 
70
71
  if (getPermissionState(SPEECH_RECOGNITION) != PermissionState.GRANTED) {
72
+ Logger.warn(TAG, "start() missing RECORD_AUDIO permission");
71
73
  call.reject(MISSING_PERMISSION);
72
74
  return;
73
75
  }
@@ -78,11 +80,23 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
78
80
  boolean partialResults = call.getBoolean("partialResults", false);
79
81
  boolean popup = call.getBoolean("popup", false);
80
82
  int allowForSilence = call.getInt("allowForSilence", 0);
83
+ Logger.info(
84
+ TAG,
85
+ String.format(
86
+ "Starting recognition | lang=%s maxResults=%d partial=%s popup=%s allowForSilence=%d",
87
+ language,
88
+ maxResults,
89
+ partialResults,
90
+ popup,
91
+ allowForSilence
92
+ )
93
+ );
81
94
  beginListening(language, maxResults, prompt, partialResults, popup, call, allowForSilence);
82
95
  }
83
96
 
84
97
  @PluginMethod
85
98
  public void stop(final PluginCall call) {
99
+ Logger.info(TAG, "stop() requested");
86
100
  try {
87
101
  stopListening();
88
102
  } catch (Exception ex) {
@@ -229,6 +243,7 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
229
243
  try {
230
244
  lock.lock();
231
245
  if (listening) {
246
+ Logger.debug(TAG, "Stopping inline recognizer");
232
247
  speechRecognizer.stopListening();
233
248
  listening(false);
234
249
  }
@@ -280,6 +295,7 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
280
295
  JSObject ret = new JSObject();
281
296
  ret.put("status", "started");
282
297
  notifyListeners(LISTENING_EVENT, ret);
298
+ Logger.debug(TAG, "Listening started");
283
299
  } finally {
284
300
  lock.unlock();
285
301
  }
@@ -313,6 +329,7 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
313
329
  public void onError(int error) {
314
330
  stopListening();
315
331
  String errorMssg = getErrorText(error);
332
+ Logger.error(TAG, "Recognizer error: " + errorMssg, null);
316
333
 
317
334
  if (call != null) {
318
335
  call.reject(errorMssg);
@@ -325,6 +342,7 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
325
342
 
326
343
  try {
327
344
  JSArray jsArray = new JSArray(matches);
345
+ Logger.debug(TAG, "Received final results count=" + (matches == null ? 0 : matches.size()));
328
346
 
329
347
  if (call != null) {
330
348
  if (!partialResults) {
@@ -353,6 +371,7 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
353
371
  JSObject ret = new JSObject();
354
372
  ret.put("matches", previousPartialResults);
355
373
  notifyListeners(PARTIAL_RESULTS_EVENT, ret);
374
+ Logger.debug(TAG, "Partial results updated");
356
375
  }
357
376
  } catch (Exception ex) {}
358
377
  }
@@ -367,12 +386,14 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
367
386
  JSObject ret = new JSObject();
368
387
  ret.put("matches", new JSArray(matches));
369
388
  notifyListeners(SEGMENT_RESULTS_EVENT, ret);
389
+ Logger.debug(TAG, "Segment results emitted");
370
390
  } catch (Exception ignored) {}
371
391
  }
372
392
 
373
393
  @Override
374
394
  public void onEndOfSegmentedSession() {
375
395
  notifyListeners(END_OF_SEGMENT_EVENT, new JSObject());
396
+ Logger.debug(TAG, "Segmented session ended");
376
397
  }
377
398
 
378
399
  @Override
@@ -41,11 +41,13 @@ public final class SpeechRecognitionPlugin: CAPPlugin, CAPBridgedPlugin {
41
41
 
42
42
  @objc func start(_ call: CAPPluginCall) {
43
43
  if self.audioEngine.isRunning || recognitionTask != nil {
44
+ CAPLog.print("[SpeechRecognition] Attempted to start while already running")
44
45
  call.reject("Speech recognition is already running.")
45
46
  return
46
47
  }
47
48
 
48
49
  guard isSpeechPermissionGranted else {
50
+ CAPLog.print("[SpeechRecognition] Missing speech permission, rejecting start()")
49
51
  call.reject("Missing speech recognition permission.")
50
52
  return
51
53
  }
@@ -59,9 +61,11 @@ public final class SpeechRecognitionPlugin: CAPPlugin, CAPBridgedPlugin {
59
61
 
60
62
  self.activeCall = call
61
63
  self.currentOptions = options
64
+ CAPLog.print("[SpeechRecognition] Starting session | language=\(options.language) partialResults=\(options.partialResults) punctuation=\(options.addPunctuation)")
62
65
 
63
66
  AVAudioSession.sharedInstance().requestRecordPermission { granted in
64
67
  guard granted else {
68
+ CAPLog.print("[SpeechRecognition] Microphone permission denied by user")
65
69
  DispatchQueue.main.async {
66
70
  call.reject("User denied microphone access.")
67
71
  self.cleanupRecognition(notifyStop: false)
@@ -76,6 +80,7 @@ public final class SpeechRecognitionPlugin: CAPPlugin, CAPBridgedPlugin {
76
80
  }
77
81
 
78
82
  @objc func stop(_ call: CAPPluginCall) {
83
+ CAPLog.print("[SpeechRecognition] stop() invoked")
79
84
  cleanupRecognition(notifyStop: true)
80
85
  call.resolve()
81
86
  }
@@ -209,6 +214,7 @@ public final class SpeechRecognitionPlugin: CAPPlugin, CAPBridgedPlugin {
209
214
 
210
215
  private func cleanupRecognition(notifyStop: Bool) {
211
216
  DispatchQueue.main.async {
217
+ CAPLog.print("[SpeechRecognition] Cleaning up recognition resources")
212
218
  if self.audioEngine.isRunning {
213
219
  self.audioEngine.stop()
214
220
  }
@@ -234,6 +240,7 @@ public final class SpeechRecognitionPlugin: CAPPlugin, CAPBridgedPlugin {
234
240
 
235
241
  private func handleRecognitionError(_ error: Error) {
236
242
  DispatchQueue.main.async {
243
+ CAPLog.print("[SpeechRecognition] Error from recognizer: \(error.localizedDescription)")
237
244
  self.cleanupRecognition(notifyStop: true)
238
245
  self.activeCall?.reject(error.localizedDescription)
239
246
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-speech-recognition",
3
- "version": "7.0.1",
3
+ "version": "7.1.0",
4
4
  "description": "Capacitor plugin for comprehensive on-device speech recognition with live partial results.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -39,8 +39,8 @@
39
39
  "verify:web": "npm run build",
40
40
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
41
41
  "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
42
- "eslint": "eslint . --ext .ts",
43
- "prettier": "prettier \"**/*.{css,html,ts,js,java,kt}\" --plugin=prettier-plugin-java",
42
+ "eslint": "eslint . --ext ts",
43
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
44
44
  "swiftlint": "node-swiftlint",
45
45
  "docgen": "docgen --api SpeechRecognitionPlugin --output-readme README.md --output-json dist/docs.json",
46
46
  "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",