@capgo/capacitor-speech-recognition 8.0.8 → 8.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.
@@ -30,7 +30,7 @@ android {
30
30
  buildTypes {
31
31
  release {
32
32
  minifyEnabled false
33
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
34
34
  }
35
35
  }
36
36
  lintOptions {
@@ -346,7 +346,7 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
346
346
 
347
347
  @Override
348
348
  public void onResults(Bundle results) {
349
- ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
349
+ ArrayList<String> matches = buildMatchesWithUnstableText(results);
350
350
 
351
351
  try {
352
352
  JSArray jsArray = new JSArray(matches);
@@ -370,18 +370,54 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
370
370
 
371
371
  @Override
372
372
  public void onPartialResults(Bundle partialResultsBundle) {
373
- ArrayList<String> matches = partialResultsBundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
374
- JSArray matchesJSON = new JSArray(matches);
373
+ ArrayList<String> matches = buildMatchesWithUnstableText(partialResultsBundle);
374
+ if (matches == null || matches.isEmpty()) {
375
+ return;
376
+ }
375
377
 
376
378
  try {
377
- if (matches != null && matches.size() > 0 && !previousPartialResults.equals(matchesJSON)) {
379
+ JSArray matchesJSON = new JSArray(matches);
380
+ if (!previousPartialResults.equals(matchesJSON)) {
378
381
  previousPartialResults = matchesJSON;
379
382
  JSObject ret = new JSObject();
380
383
  ret.put("matches", previousPartialResults);
381
384
  notifyListeners(PARTIAL_RESULTS_EVENT, ret);
382
385
  Logger.debug(TAG, "Partial results updated");
383
386
  }
384
- } catch (Exception ex) {}
387
+ } catch (Exception ex) {
388
+ Logger.error(TAG, "onPartialResults failed", ex);
389
+ }
390
+ }
391
+
392
+ private ArrayList<String> buildMatchesWithUnstableText(Bundle resultsBundle) {
393
+ ArrayList<String> matches = resultsBundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
394
+ if (matches == null || matches.isEmpty()) {
395
+ return matches;
396
+ }
397
+
398
+ String unstableText = resultsBundle.getString("android.speech.extra.UNSTABLE_TEXT");
399
+ if (unstableText != null) {
400
+ String trimmedUnstable = unstableText.trim();
401
+ if (trimmedUnstable.isEmpty()) {
402
+ return matches;
403
+ }
404
+
405
+ String firstMatch = matches.get(0);
406
+ if (firstMatch == null) {
407
+ return matches;
408
+ }
409
+
410
+ String trimmedFirstMatch = firstMatch.trim();
411
+ if (trimmedFirstMatch.equals(trimmedUnstable) || trimmedFirstMatch.endsWith(" " + trimmedUnstable)) {
412
+ return matches;
413
+ }
414
+
415
+ ArrayList<String> mergedMatches = new ArrayList<>(matches);
416
+ mergedMatches.set(0, trimmedFirstMatch + " " + trimmedUnstable);
417
+ return mergedMatches;
418
+ }
419
+
420
+ return matches;
385
421
  }
386
422
 
387
423
  @Override
@@ -11,7 +11,7 @@ private enum PermissionState: String {
11
11
 
12
12
  @objc(SpeechRecognitionPlugin)
13
13
  public final class SpeechRecognitionPlugin: CAPPlugin, CAPBridgedPlugin {
14
- private let pluginVersion: String = "8.0.8"
14
+ private let pluginVersion: String = "8.0.10"
15
15
  public let identifier = "SpeechRecognitionPlugin"
16
16
  public let jsName = "SpeechRecognition"
17
17
  public let pluginMethods: [CAPPluginMethod] = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-speech-recognition",
3
- "version": "8.0.8",
3
+ "version": "8.0.10",
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",