@capgo/capacitor-speech-recognition 8.1.7 → 8.1.8
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.
- package/README.md +5 -3
- package/android/src/main/java/app/capgo/speechrecognition/Constants.java +1 -0
- package/android/src/main/java/app/capgo/speechrecognition/SpeechRecognitionPlugin.java +96 -1
- package/dist/docs.json +14 -0
- package/dist/esm/definitions.d.ts +16 -0
- package/dist/esm/definitions.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -567,6 +567,7 @@ Configure how the recognizer behaves when calling {@link SpeechRecognitionPlugin
|
|
|
567
567
|
| **`useOnDeviceRecognition`** | <code>boolean</code> | Opt in to the platform's newer on-device recognition path when available. On iOS 26+, this uses Apple's `SpeechAnalyzer` / `SpeechTranscriber` pipeline. On recent Android versions, this uses the on-device `SpeechRecognizer` path. It is intentionally opt-in so existing apps keep the legacy flow unless they choose to roll out the new behavior. On iOS, leaving this disabled keeps `SFSpeechRecognizer` on every supported OS version. Enabling it on older iOS versions or unsupported locales falls back to `SFSpeechRecognizer`. Use {@link SpeechRecognitionPlugin.isOnDeviceRecognitionAvailable} before enabling it in production. Platform SDK docs: iOS: [Speech](https://developer.apple.com/documentation/speech), [SpeechAnalyzer](https://developer.apple.com/documentation/speech/speechanalyzer), [SpeechTranscriber](https://developer.apple.com/documentation/speech/speechtranscriber) Android: [SpeechRecognizer](https://developer.android.com/reference/android/speech/SpeechRecognizer) Defaults to `false`. |
|
|
568
568
|
| **`allowForSilence`** | <code>number</code> | Allow a number of milliseconds of silence before splitting the recognition session into segments. Required to be greater than zero and currently supported on Android only. |
|
|
569
569
|
| **`continuousPTT`** | <code>boolean</code> | EXPERIMENTAL: Keep a PTT session alive across silence by restarting recognition while the button stays held. This restart behavior is implemented for Android inline recognition and iOS native recognition. |
|
|
570
|
+
| **`muteRecognizerBeep`** | <code>boolean</code> | Suppresses the Android system beep when inline recognition starts or restarts. Uses a best-effort combination of an undocumented recognizer intent extra and temporary notification/system stream volume muting. Some devices ignore the intent extra; the volume fallback is the portable path. Defaults to `true` when `continuousPTT` is enabled. |
|
|
570
571
|
|
|
571
572
|
|
|
572
573
|
#### SpeechRecognitionMatches
|
|
@@ -600,9 +601,10 @@ Result from {@link SpeechRecognitionPlugin.getLastPartialResult}.
|
|
|
600
601
|
|
|
601
602
|
Options for {@link SpeechRecognitionPlugin.setPTTState}.
|
|
602
603
|
|
|
603
|
-
| Prop | Type | Description
|
|
604
|
-
| ---------- | -------------------- |
|
|
605
|
-
| **`held`** | <code>boolean</code> | Whether the PTT button is currently held.
|
|
604
|
+
| Prop | Type | Description |
|
|
605
|
+
| ---------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
606
|
+
| **`held`** | <code>boolean</code> | Whether the PTT button is currently held. |
|
|
607
|
+
| **`mute`** | <code>boolean</code> | When set, updates whether Android should suppress the recognizer start beep for the active session. Beep suppression is best-effort and device-specific; see {@link <a href="#speechrecognitionstartoptions">SpeechRecognitionStartOptions.muteRecognizerBeep</a>}. |
|
|
606
608
|
|
|
607
609
|
|
|
608
610
|
#### SpeechRecognitionLanguages
|
|
@@ -16,4 +16,5 @@ public interface Constants {
|
|
|
16
16
|
String READY_FOR_NEXT_SESSION_EVENT = "readyForNextSession";
|
|
17
17
|
String RECORD_AUDIO_PERMISSION = Manifest.permission.RECORD_AUDIO;
|
|
18
18
|
String LANGUAGE_ERROR = "Could not get list of languages";
|
|
19
|
+
String EXTRA_DICTATE_BEEP = "android.speech.extra.DICTATE_BEEP";
|
|
19
20
|
}
|
|
@@ -2,7 +2,9 @@ package app.capgo.speechrecognition;
|
|
|
2
2
|
|
|
3
3
|
import android.Manifest;
|
|
4
4
|
import android.app.Activity;
|
|
5
|
+
import android.content.Context;
|
|
5
6
|
import android.content.Intent;
|
|
7
|
+
import android.media.AudioManager;
|
|
6
8
|
import android.os.Build;
|
|
7
9
|
import android.os.Bundle;
|
|
8
10
|
import android.os.Handler;
|
|
@@ -64,6 +66,10 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
|
|
|
64
66
|
private boolean forceStopped = false;
|
|
65
67
|
private boolean pttButtonHeld = false;
|
|
66
68
|
private boolean continuousPTTMode = false;
|
|
69
|
+
private boolean muteRecognizerBeep = false;
|
|
70
|
+
private Integer savedNotificationVolume;
|
|
71
|
+
private Integer savedSystemVolume;
|
|
72
|
+
private long mutedForGeneration = -1;
|
|
67
73
|
private boolean popupSessionActive = false;
|
|
68
74
|
private boolean popupSessionCancelled = false;
|
|
69
75
|
private StringBuilder accumulatedResults = new StringBuilder();
|
|
@@ -164,6 +170,7 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
|
|
|
164
170
|
boolean useOnDeviceRecognition = call.getBoolean("useOnDeviceRecognition", false);
|
|
165
171
|
int allowForSilence = call.getInt("allowForSilence", 0);
|
|
166
172
|
boolean continuousPTT = call.getBoolean("continuousPTT", false);
|
|
173
|
+
boolean muteRecognizerBeepOption = call.getBoolean("muteRecognizerBeep", continuousPTT);
|
|
167
174
|
|
|
168
175
|
if (useOnDeviceRecognition && popup) {
|
|
169
176
|
call.reject("On-device recognition is not supported with popup mode on Android.");
|
|
@@ -198,6 +205,7 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
|
|
|
198
205
|
resetPartialResultsCache();
|
|
199
206
|
accumulatedResults = new StringBuilder();
|
|
200
207
|
continuousPTTMode = continuousPTT;
|
|
208
|
+
muteRecognizerBeep = muteRecognizerBeepOption;
|
|
201
209
|
popupSessionActive = false;
|
|
202
210
|
popupSessionCancelled = false;
|
|
203
211
|
lastLanguage = language;
|
|
@@ -409,6 +417,9 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
|
|
|
409
417
|
try {
|
|
410
418
|
lock.lock();
|
|
411
419
|
pttButtonHeld = held;
|
|
420
|
+
if (call.getData().has("mute")) {
|
|
421
|
+
muteRecognizerBeep = call.getBoolean("mute");
|
|
422
|
+
}
|
|
412
423
|
if (held) {
|
|
413
424
|
accumulatedResults = new StringBuilder();
|
|
414
425
|
forceStopped = false;
|
|
@@ -596,6 +607,11 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
|
|
|
596
607
|
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
|
|
597
608
|
}
|
|
598
609
|
|
|
610
|
+
// EXTRA_DICTATE_BEEP is undocumented and ignored on some devices; AudioManager fallback handles those.
|
|
611
|
+
if (muteRecognizerBeep) {
|
|
612
|
+
intent.putExtra(EXTRA_DICTATE_BEEP, false);
|
|
613
|
+
}
|
|
614
|
+
|
|
599
615
|
return intent;
|
|
600
616
|
}
|
|
601
617
|
|
|
@@ -722,7 +738,29 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
|
|
|
722
738
|
}
|
|
723
739
|
|
|
724
740
|
private void startInlineListening(Intent intent, boolean partialResults, PluginCall call, long currentSessionId, boolean restarting) {
|
|
741
|
+
final long muteGeneration;
|
|
742
|
+
try {
|
|
743
|
+
lock.lock();
|
|
744
|
+
muteGeneration = recognizerGeneration;
|
|
745
|
+
muteRecognizerBeepIfNeededLocked(muteGeneration);
|
|
746
|
+
} finally {
|
|
747
|
+
lock.unlock();
|
|
748
|
+
}
|
|
725
749
|
speechRecognizer.startListening(intent);
|
|
750
|
+
handler.postDelayed(
|
|
751
|
+
() -> {
|
|
752
|
+
try {
|
|
753
|
+
lock.lock();
|
|
754
|
+
if (currentSessionId != sessionId) {
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
restoreRecognizerBeepIfNeededLocked(muteGeneration);
|
|
758
|
+
} finally {
|
|
759
|
+
lock.unlock();
|
|
760
|
+
}
|
|
761
|
+
},
|
|
762
|
+
750
|
|
763
|
+
);
|
|
726
764
|
listening(true);
|
|
727
765
|
state = ListeningState.STARTED;
|
|
728
766
|
emitListeningState("started", currentSessionId, restarting ? "results" : "userStart", null, "started");
|
|
@@ -781,6 +819,7 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
|
|
|
781
819
|
|
|
782
820
|
cancelPendingForceStopLocked();
|
|
783
821
|
listening(false);
|
|
822
|
+
restoreRecognizerBeepIfNeededLocked(mutedForGeneration);
|
|
784
823
|
if (activeStartCall != null && !lastPartialResults && ("userStop".equals(reason) || "forceStop".equals(reason))) {
|
|
785
824
|
startCallToReject = activeStartCall;
|
|
786
825
|
}
|
|
@@ -972,6 +1011,7 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
|
|
|
972
1011
|
handler.removeCallbacksAndMessages(null);
|
|
973
1012
|
try {
|
|
974
1013
|
lock.lock();
|
|
1014
|
+
restoreRecognizerBeepIfNeededLocked(mutedForGeneration);
|
|
975
1015
|
destroyCurrentRecognizerLocked();
|
|
976
1016
|
activeStartCall = null;
|
|
977
1017
|
pendingStopReason = null;
|
|
@@ -984,6 +1024,51 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
|
|
|
984
1024
|
}
|
|
985
1025
|
}
|
|
986
1026
|
|
|
1027
|
+
private void muteRecognizerBeepIfNeededLocked(long generation) {
|
|
1028
|
+
if (!muteRecognizerBeep) {
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
|
|
1033
|
+
if (audioManager == null) {
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
try {
|
|
1038
|
+
if (savedNotificationVolume == null) {
|
|
1039
|
+
savedNotificationVolume = audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
|
|
1040
|
+
savedSystemVolume = audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM);
|
|
1041
|
+
mutedForGeneration = generation;
|
|
1042
|
+
}
|
|
1043
|
+
audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0);
|
|
1044
|
+
audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, 0, 0);
|
|
1045
|
+
} catch (SecurityException ex) {
|
|
1046
|
+
Logger.warn(TAG, "Unable to mute recognizer beep: " + ex.getMessage());
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
private void restoreRecognizerBeepIfNeededLocked(long generation) {
|
|
1051
|
+
if (savedNotificationVolume == null || generation != mutedForGeneration) {
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
|
|
1056
|
+
if (audioManager != null) {
|
|
1057
|
+
try {
|
|
1058
|
+
audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, savedNotificationVolume, 0);
|
|
1059
|
+
if (savedSystemVolume != null) {
|
|
1060
|
+
audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, savedSystemVolume, 0);
|
|
1061
|
+
}
|
|
1062
|
+
} catch (SecurityException ex) {
|
|
1063
|
+
Logger.warn(TAG, "Unable to restore recognizer beep volume: " + ex.getMessage());
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
savedNotificationVolume = null;
|
|
1068
|
+
savedSystemVolume = null;
|
|
1069
|
+
mutedForGeneration = -1;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
987
1072
|
private class SpeechRecognitionListener implements RecognitionListener {
|
|
988
1073
|
|
|
989
1074
|
private final long listenerSessionId;
|
|
@@ -1005,7 +1090,17 @@ public class SpeechRecognitionPlugin extends Plugin implements Constants {
|
|
|
1005
1090
|
}
|
|
1006
1091
|
|
|
1007
1092
|
@Override
|
|
1008
|
-
public void onReadyForSpeech(Bundle params) {
|
|
1093
|
+
public void onReadyForSpeech(Bundle params) {
|
|
1094
|
+
if (isStale()) {
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
try {
|
|
1098
|
+
lock.lock();
|
|
1099
|
+
restoreRecognizerBeepIfNeededLocked(listenerGeneration);
|
|
1100
|
+
} finally {
|
|
1101
|
+
lock.unlock();
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1009
1104
|
|
|
1010
1105
|
@Override
|
|
1011
1106
|
public void onBeginningOfSpeech() {}
|
package/dist/docs.json
CHANGED
|
@@ -421,6 +421,13 @@
|
|
|
421
421
|
"docs": "EXPERIMENTAL: Keep a PTT session alive across silence by restarting recognition while the button stays held.\n\nThis restart behavior is implemented for Android inline recognition and iOS native recognition.",
|
|
422
422
|
"complexTypes": [],
|
|
423
423
|
"type": "boolean | undefined"
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
"name": "muteRecognizerBeep",
|
|
427
|
+
"tags": [],
|
|
428
|
+
"docs": "Suppresses the Android system beep when inline recognition starts or restarts.\n\nUses a best-effort combination of an undocumented recognizer intent extra and\ntemporary notification/system stream volume muting. Some devices ignore the\nintent extra; the volume fallback is the portable path.\n\nDefaults to `true` when `continuousPTT` is enabled.",
|
|
429
|
+
"complexTypes": [],
|
|
430
|
+
"type": "boolean | undefined"
|
|
424
431
|
}
|
|
425
432
|
]
|
|
426
433
|
},
|
|
@@ -499,6 +506,13 @@
|
|
|
499
506
|
"docs": "Whether the PTT button is currently held.",
|
|
500
507
|
"complexTypes": [],
|
|
501
508
|
"type": "boolean"
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
"name": "mute",
|
|
512
|
+
"tags": [],
|
|
513
|
+
"docs": "When set, updates whether Android should suppress the recognizer start beep for the active session.\n\nBeep suppression is best-effort and device-specific; see {@link SpeechRecognitionStartOptions.muteRecognizerBeep}.",
|
|
514
|
+
"complexTypes": [],
|
|
515
|
+
"type": "boolean | undefined"
|
|
502
516
|
}
|
|
503
517
|
]
|
|
504
518
|
},
|
|
@@ -81,6 +81,16 @@ export interface SpeechRecognitionStartOptions {
|
|
|
81
81
|
* This restart behavior is implemented for Android inline recognition and iOS native recognition.
|
|
82
82
|
*/
|
|
83
83
|
continuousPTT?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Suppresses the Android system beep when inline recognition starts or restarts.
|
|
86
|
+
*
|
|
87
|
+
* Uses a best-effort combination of an undocumented recognizer intent extra and
|
|
88
|
+
* temporary notification/system stream volume muting. Some devices ignore the
|
|
89
|
+
* intent extra; the volume fallback is the portable path.
|
|
90
|
+
*
|
|
91
|
+
* Defaults to `true` when `continuousPTT` is enabled.
|
|
92
|
+
*/
|
|
93
|
+
muteRecognizerBeep?: boolean;
|
|
84
94
|
}
|
|
85
95
|
/**
|
|
86
96
|
* Raised whenever a partial transcription is produced.
|
|
@@ -215,6 +225,12 @@ export interface PTTStateOptions {
|
|
|
215
225
|
* Whether the PTT button is currently held.
|
|
216
226
|
*/
|
|
217
227
|
held: boolean;
|
|
228
|
+
/**
|
|
229
|
+
* When set, updates whether Android should suppress the recognizer start beep for the active session.
|
|
230
|
+
*
|
|
231
|
+
* Beep suppression is best-effort and device-specific; see {@link SpeechRecognitionStartOptions.muteRecognizerBeep}.
|
|
232
|
+
*/
|
|
233
|
+
mute?: boolean;
|
|
218
234
|
}
|
|
219
235
|
export interface SpeechRecognitionPlugin {
|
|
220
236
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionState, PluginListenerHandle } from '@capacitor/core';\n\n/**\n * Permission map returned by `checkPermissions` and `requestPermissions`.\n *\n * On Android the state maps to the `RECORD_AUDIO` permission.\n * On iOS it combines speech recognition plus microphone permission.\n */\nexport interface SpeechRecognitionPermissionStatus {\n speechRecognition: PermissionState;\n}\n\n/**\n * Configure how the recognizer behaves when calling {@link SpeechRecognitionPlugin.start}.\n */\nexport interface SpeechRecognitionStartOptions {\n /**\n * Locale identifier such as `en-US`. When omitted the device language is used.\n */\n language?: string;\n /**\n * Maximum number of final matches returned by native APIs. Defaults to `5`.\n */\n maxResults?: number;\n /**\n * Prompt message shown inside the Android system dialog (ignored on iOS).\n */\n prompt?: string;\n /**\n * When `true`, Android shows the OS speech dialog instead of running inline recognition.\n * Defaults to `false`.\n */\n popup?: boolean;\n /**\n * Emits partial transcription updates through the `partialResults` listener while audio is captured.\n */\n partialResults?: boolean;\n /**\n * Enables native punctuation handling where supported (iOS 16+).\n */\n addPunctuation?: boolean;\n /**\n * Words or phrases that should be recognized more accurately by native speech APIs.\n *\n * On iOS, these are passed to `SFSpeechRecognitionRequest.contextualStrings`\n * when the plugin uses the legacy `SFSpeechRecognizer` path. That path is the\n * default on all iOS versions, the fallback below iOS 26, and still available\n * on iOS 26+ by leaving `useOnDeviceRecognition` disabled.\n *\n * Ignored by Android and by the iOS 26+ `SpeechAnalyzer` path.\n */\n contextualStrings?: string[];\n /**\n * Opt in to the platform's newer on-device recognition path when available.\n *\n * On iOS 26+, this uses Apple's `SpeechAnalyzer` / `SpeechTranscriber` pipeline.\n * On recent Android versions, this uses the on-device `SpeechRecognizer` path.\n *\n * It is intentionally opt-in so existing apps keep the legacy flow unless they choose\n * to roll out the new behavior.\n * On iOS, leaving this disabled keeps `SFSpeechRecognizer` on every supported OS version.\n * Enabling it on older iOS versions or unsupported locales falls back to `SFSpeechRecognizer`.\n *\n * Use {@link SpeechRecognitionPlugin.isOnDeviceRecognitionAvailable} before enabling it in production.\n *\n * Platform SDK docs:\n * iOS: [Speech](https://developer.apple.com/documentation/speech),\n * [SpeechAnalyzer](https://developer.apple.com/documentation/speech/speechanalyzer),\n * [SpeechTranscriber](https://developer.apple.com/documentation/speech/speechtranscriber)\n * Android: [SpeechRecognizer](https://developer.android.com/reference/android/speech/SpeechRecognizer)\n *\n * Defaults to `false`.\n */\n useOnDeviceRecognition?: boolean;\n /**\n * Allow a number of milliseconds of silence before splitting the recognition session into segments.\n * Required to be greater than zero and currently supported on Android only.\n */\n allowForSilence?: number;\n /**\n * EXPERIMENTAL: Keep a PTT session alive across silence by restarting recognition while the button stays held.\n *\n * This restart behavior is implemented for Android inline recognition and iOS native recognition.\n */\n continuousPTT?: boolean;\n}\n\n/**\n * Raised whenever a partial transcription is produced.\n */\nexport interface SpeechRecognitionPartialResultEvent {\n /**\n * Current recognition matches when the native recognizer reports them.\n *\n * This can be omitted for forced or accumulated-only payloads.\n */\n matches?: string[];\n /**\n * Accumulated transcription from earlier continuous PTT cycles.\n */\n accumulated?: string;\n /**\n * Final accumulated text including the current result.\n */\n accumulatedText?: string;\n /**\n * `true` when the plugin is restarting recognition inside a continuous PTT session.\n */\n isRestarting?: boolean;\n /**\n * `true` when the payload was emitted by `forceStop()`.\n */\n forced?: boolean;\n}\n\n/**\n * Raised whenever a segmented result is produced (Android only).\n */\nexport interface SpeechRecognitionSegmentResultEvent {\n matches: string[];\n}\n\n/**\n * Finite state values for the recognition session lifecycle.\n */\nexport type ListeningFiniteState = 'startingListening' | 'started' | 'stoppingListening' | 'stopped';\n\n/**\n * Why a listening state transition happened.\n */\nexport type ListeningReason = 'userStart' | 'userStop' | 'forceStop' | 'results' | 'silence' | 'error' | 'unknown';\n\n/**\n * Raised when the listening state changes.\n *\n * The original `status` field is preserved for backward compatibility and is present\n * on the binary `started` / `stopped` states.\n */\nexport interface SpeechRecognitionListeningEvent {\n /**\n * Finite state of the recognition session.\n */\n state?: ListeningFiniteState;\n /**\n * Unique identifier for the current listening session.\n */\n sessionId?: number;\n /**\n * Why this state transition occurred.\n */\n reason?: ListeningReason;\n /**\n * Error code when the transition is caused by an error.\n */\n errorCode?: string;\n /**\n * Backward-compatible binary state used by earlier releases.\n */\n status?: 'started' | 'stopped';\n}\n\n/**\n * Raised whenever native recognition reports an error.\n */\nexport interface SpeechRecognitionErrorEvent {\n code: string;\n message: string;\n sessionId: number;\n}\n\n/**\n * Emitted after native resources have been torn down and the plugin is ready for another session.\n */\nexport interface SpeechRecognitionReadyEvent {\n sessionId: number;\n}\n\nexport interface SpeechRecognitionAvailability {\n available: boolean;\n}\n\nexport interface SpeechRecognitionMatches {\n matches?: string[];\n}\n\nexport interface SpeechRecognitionLanguages {\n languages: string[];\n}\n\nexport interface SpeechRecognitionListening {\n listening: boolean;\n}\n\n/**\n * Options for {@link SpeechRecognitionPlugin.forceStop}.\n */\nexport interface ForceStopOptions {\n /**\n * Android only: timeout in milliseconds before forcing stop via destroy/recreate.\n *\n * On iOS, the current session is stopped immediately and this value is ignored.\n *\n * Defaults to `1500`.\n */\n timeout?: number;\n}\n\n/**\n * Result from {@link SpeechRecognitionPlugin.getLastPartialResult}.\n */\nexport interface LastPartialResult {\n /**\n * Whether a partial result is currently cached.\n */\n available: boolean;\n /**\n * The most recent transcript text known to the native recognizer.\n */\n text: string;\n /**\n * All current match alternatives when available.\n */\n matches?: string[];\n}\n\n/**\n * Options for {@link SpeechRecognitionPlugin.setPTTState}.\n */\nexport interface PTTStateOptions {\n /**\n * Whether the PTT button is currently held.\n */\n held: boolean;\n}\n\nexport interface SpeechRecognitionPlugin {\n /**\n * Checks whether the native speech recognition service is usable on the current device.\n */\n available(): Promise<SpeechRecognitionAvailability>;\n /**\n * Checks whether the platform's newer on-device recognition path is available for the selected locale.\n *\n * This is the capability check you should use before enabling `useOnDeviceRecognition`.\n * A `true` result means the current device, OS version, and locale can use the newer\n * on-device path for that platform.\n *\n * Returns `false` when the device only supports the legacy recognizer path.\n *\n * Platform SDK docs:\n * iOS: [Speech](https://developer.apple.com/documentation/speech)\n * Android: [SpeechRecognizer](https://developer.android.com/reference/android/speech/SpeechRecognizer)\n */\n isOnDeviceRecognitionAvailable(\n options?: Pick<SpeechRecognitionStartOptions, 'language'>,\n ): Promise<SpeechRecognitionAvailability>;\n /**\n * Begins capturing audio and transcribing speech.\n *\n * When `partialResults` is `true`, the returned promise resolves immediately and updates are\n * streamed through the `partialResults` listener until the session ends.\n *\n * The default path keeps the legacy recognizer behavior for backward compatibility.\n * Pass `useOnDeviceRecognition: true` only after checking\n * {@link SpeechRecognitionPlugin.isOnDeviceRecognitionAvailable}.\n */\n start(options?: SpeechRecognitionStartOptions): Promise<SpeechRecognitionMatches>;\n /**\n * Stops listening and tears down native resources.\n */\n stop(): Promise<void>;\n /**\n * Force stops the current session.\n *\n * On Android, this first tries a normal stop and then falls back to destroy/recreate after `timeout`.\n * On iOS, the current session is stopped immediately.\n *\n * If a partial transcript is cached, it is emitted through the `partialResults` listener with `forced: true`.\n */\n forceStop(options?: ForceStopOptions): Promise<void>;\n /**\n * Gets the last cached partial transcription result.\n */\n getLastPartialResult(): Promise<LastPartialResult>;\n /**\n * Updates the current push-to-talk button state.\n *\n * Use this together with `continuousPTT` or with a custom hold-to-talk flow.\n */\n setPTTState(options: PTTStateOptions): Promise<void>;\n /**\n * Gets the locales supported by the underlying recognizer.\n *\n * Android 13+ devices no longer expose this list; in that case `languages` is empty.\n */\n getSupportedLanguages(): Promise<SpeechRecognitionLanguages>;\n /**\n * Returns whether the plugin is actively listening for speech.\n */\n isListening(): Promise<SpeechRecognitionListening>;\n /**\n * Gets the current permission state.\n */\n checkPermissions(): Promise<SpeechRecognitionPermissionStatus>;\n /**\n * Requests the microphone + speech recognition permissions.\n */\n requestPermissions(): Promise<SpeechRecognitionPermissionStatus>;\n /**\n * Returns the native plugin version bundled with this package.\n *\n * Useful when reporting issues to confirm that native and JS versions match.\n */\n getPluginVersion(): Promise<{ version: string }>;\n /**\n * Listen for segmented session completion events (Android only).\n */\n addListener(eventName: 'endOfSegmentedSession', listenerFunc: () => void): Promise<PluginListenerHandle>;\n /**\n * Listen for segmented recognition results (Android only).\n */\n addListener(\n eventName: 'segmentResults',\n listenerFunc: (event: SpeechRecognitionSegmentResultEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Listen for partial transcription updates emitted while `partialResults` is enabled.\n */\n addListener(\n eventName: 'partialResults',\n listenerFunc: (event: SpeechRecognitionPartialResultEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Listen for changes to the native listening state.\n */\n addListener(\n eventName: 'listeningState',\n listenerFunc: (event: SpeechRecognitionListeningEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Listen for recognition errors.\n */\n addListener(\n eventName: 'error',\n listenerFunc: (event: SpeechRecognitionErrorEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Listen for the recognizer becoming ready for another session.\n */\n addListener(\n eventName: 'readyForNextSession',\n listenerFunc: (event: SpeechRecognitionReadyEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Removes every registered listener.\n */\n removeAllListeners(): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionState, PluginListenerHandle } from '@capacitor/core';\n\n/**\n * Permission map returned by `checkPermissions` and `requestPermissions`.\n *\n * On Android the state maps to the `RECORD_AUDIO` permission.\n * On iOS it combines speech recognition plus microphone permission.\n */\nexport interface SpeechRecognitionPermissionStatus {\n speechRecognition: PermissionState;\n}\n\n/**\n * Configure how the recognizer behaves when calling {@link SpeechRecognitionPlugin.start}.\n */\nexport interface SpeechRecognitionStartOptions {\n /**\n * Locale identifier such as `en-US`. When omitted the device language is used.\n */\n language?: string;\n /**\n * Maximum number of final matches returned by native APIs. Defaults to `5`.\n */\n maxResults?: number;\n /**\n * Prompt message shown inside the Android system dialog (ignored on iOS).\n */\n prompt?: string;\n /**\n * When `true`, Android shows the OS speech dialog instead of running inline recognition.\n * Defaults to `false`.\n */\n popup?: boolean;\n /**\n * Emits partial transcription updates through the `partialResults` listener while audio is captured.\n */\n partialResults?: boolean;\n /**\n * Enables native punctuation handling where supported (iOS 16+).\n */\n addPunctuation?: boolean;\n /**\n * Words or phrases that should be recognized more accurately by native speech APIs.\n *\n * On iOS, these are passed to `SFSpeechRecognitionRequest.contextualStrings`\n * when the plugin uses the legacy `SFSpeechRecognizer` path. That path is the\n * default on all iOS versions, the fallback below iOS 26, and still available\n * on iOS 26+ by leaving `useOnDeviceRecognition` disabled.\n *\n * Ignored by Android and by the iOS 26+ `SpeechAnalyzer` path.\n */\n contextualStrings?: string[];\n /**\n * Opt in to the platform's newer on-device recognition path when available.\n *\n * On iOS 26+, this uses Apple's `SpeechAnalyzer` / `SpeechTranscriber` pipeline.\n * On recent Android versions, this uses the on-device `SpeechRecognizer` path.\n *\n * It is intentionally opt-in so existing apps keep the legacy flow unless they choose\n * to roll out the new behavior.\n * On iOS, leaving this disabled keeps `SFSpeechRecognizer` on every supported OS version.\n * Enabling it on older iOS versions or unsupported locales falls back to `SFSpeechRecognizer`.\n *\n * Use {@link SpeechRecognitionPlugin.isOnDeviceRecognitionAvailable} before enabling it in production.\n *\n * Platform SDK docs:\n * iOS: [Speech](https://developer.apple.com/documentation/speech),\n * [SpeechAnalyzer](https://developer.apple.com/documentation/speech/speechanalyzer),\n * [SpeechTranscriber](https://developer.apple.com/documentation/speech/speechtranscriber)\n * Android: [SpeechRecognizer](https://developer.android.com/reference/android/speech/SpeechRecognizer)\n *\n * Defaults to `false`.\n */\n useOnDeviceRecognition?: boolean;\n /**\n * Allow a number of milliseconds of silence before splitting the recognition session into segments.\n * Required to be greater than zero and currently supported on Android only.\n */\n allowForSilence?: number;\n /**\n * EXPERIMENTAL: Keep a PTT session alive across silence by restarting recognition while the button stays held.\n *\n * This restart behavior is implemented for Android inline recognition and iOS native recognition.\n */\n continuousPTT?: boolean;\n /**\n * Suppresses the Android system beep when inline recognition starts or restarts.\n *\n * Uses a best-effort combination of an undocumented recognizer intent extra and\n * temporary notification/system stream volume muting. Some devices ignore the\n * intent extra; the volume fallback is the portable path.\n *\n * Defaults to `true` when `continuousPTT` is enabled.\n */\n muteRecognizerBeep?: boolean;\n}\n\n/**\n * Raised whenever a partial transcription is produced.\n */\nexport interface SpeechRecognitionPartialResultEvent {\n /**\n * Current recognition matches when the native recognizer reports them.\n *\n * This can be omitted for forced or accumulated-only payloads.\n */\n matches?: string[];\n /**\n * Accumulated transcription from earlier continuous PTT cycles.\n */\n accumulated?: string;\n /**\n * Final accumulated text including the current result.\n */\n accumulatedText?: string;\n /**\n * `true` when the plugin is restarting recognition inside a continuous PTT session.\n */\n isRestarting?: boolean;\n /**\n * `true` when the payload was emitted by `forceStop()`.\n */\n forced?: boolean;\n}\n\n/**\n * Raised whenever a segmented result is produced (Android only).\n */\nexport interface SpeechRecognitionSegmentResultEvent {\n matches: string[];\n}\n\n/**\n * Finite state values for the recognition session lifecycle.\n */\nexport type ListeningFiniteState = 'startingListening' | 'started' | 'stoppingListening' | 'stopped';\n\n/**\n * Why a listening state transition happened.\n */\nexport type ListeningReason = 'userStart' | 'userStop' | 'forceStop' | 'results' | 'silence' | 'error' | 'unknown';\n\n/**\n * Raised when the listening state changes.\n *\n * The original `status` field is preserved for backward compatibility and is present\n * on the binary `started` / `stopped` states.\n */\nexport interface SpeechRecognitionListeningEvent {\n /**\n * Finite state of the recognition session.\n */\n state?: ListeningFiniteState;\n /**\n * Unique identifier for the current listening session.\n */\n sessionId?: number;\n /**\n * Why this state transition occurred.\n */\n reason?: ListeningReason;\n /**\n * Error code when the transition is caused by an error.\n */\n errorCode?: string;\n /**\n * Backward-compatible binary state used by earlier releases.\n */\n status?: 'started' | 'stopped';\n}\n\n/**\n * Raised whenever native recognition reports an error.\n */\nexport interface SpeechRecognitionErrorEvent {\n code: string;\n message: string;\n sessionId: number;\n}\n\n/**\n * Emitted after native resources have been torn down and the plugin is ready for another session.\n */\nexport interface SpeechRecognitionReadyEvent {\n sessionId: number;\n}\n\nexport interface SpeechRecognitionAvailability {\n available: boolean;\n}\n\nexport interface SpeechRecognitionMatches {\n matches?: string[];\n}\n\nexport interface SpeechRecognitionLanguages {\n languages: string[];\n}\n\nexport interface SpeechRecognitionListening {\n listening: boolean;\n}\n\n/**\n * Options for {@link SpeechRecognitionPlugin.forceStop}.\n */\nexport interface ForceStopOptions {\n /**\n * Android only: timeout in milliseconds before forcing stop via destroy/recreate.\n *\n * On iOS, the current session is stopped immediately and this value is ignored.\n *\n * Defaults to `1500`.\n */\n timeout?: number;\n}\n\n/**\n * Result from {@link SpeechRecognitionPlugin.getLastPartialResult}.\n */\nexport interface LastPartialResult {\n /**\n * Whether a partial result is currently cached.\n */\n available: boolean;\n /**\n * The most recent transcript text known to the native recognizer.\n */\n text: string;\n /**\n * All current match alternatives when available.\n */\n matches?: string[];\n}\n\n/**\n * Options for {@link SpeechRecognitionPlugin.setPTTState}.\n */\nexport interface PTTStateOptions {\n /**\n * Whether the PTT button is currently held.\n */\n held: boolean;\n /**\n * When set, updates whether Android should suppress the recognizer start beep for the active session.\n *\n * Beep suppression is best-effort and device-specific; see {@link SpeechRecognitionStartOptions.muteRecognizerBeep}.\n */\n mute?: boolean;\n}\n\nexport interface SpeechRecognitionPlugin {\n /**\n * Checks whether the native speech recognition service is usable on the current device.\n */\n available(): Promise<SpeechRecognitionAvailability>;\n /**\n * Checks whether the platform's newer on-device recognition path is available for the selected locale.\n *\n * This is the capability check you should use before enabling `useOnDeviceRecognition`.\n * A `true` result means the current device, OS version, and locale can use the newer\n * on-device path for that platform.\n *\n * Returns `false` when the device only supports the legacy recognizer path.\n *\n * Platform SDK docs:\n * iOS: [Speech](https://developer.apple.com/documentation/speech)\n * Android: [SpeechRecognizer](https://developer.android.com/reference/android/speech/SpeechRecognizer)\n */\n isOnDeviceRecognitionAvailable(\n options?: Pick<SpeechRecognitionStartOptions, 'language'>,\n ): Promise<SpeechRecognitionAvailability>;\n /**\n * Begins capturing audio and transcribing speech.\n *\n * When `partialResults` is `true`, the returned promise resolves immediately and updates are\n * streamed through the `partialResults` listener until the session ends.\n *\n * The default path keeps the legacy recognizer behavior for backward compatibility.\n * Pass `useOnDeviceRecognition: true` only after checking\n * {@link SpeechRecognitionPlugin.isOnDeviceRecognitionAvailable}.\n */\n start(options?: SpeechRecognitionStartOptions): Promise<SpeechRecognitionMatches>;\n /**\n * Stops listening and tears down native resources.\n */\n stop(): Promise<void>;\n /**\n * Force stops the current session.\n *\n * On Android, this first tries a normal stop and then falls back to destroy/recreate after `timeout`.\n * On iOS, the current session is stopped immediately.\n *\n * If a partial transcript is cached, it is emitted through the `partialResults` listener with `forced: true`.\n */\n forceStop(options?: ForceStopOptions): Promise<void>;\n /**\n * Gets the last cached partial transcription result.\n */\n getLastPartialResult(): Promise<LastPartialResult>;\n /**\n * Updates the current push-to-talk button state.\n *\n * Use this together with `continuousPTT` or with a custom hold-to-talk flow.\n */\n setPTTState(options: PTTStateOptions): Promise<void>;\n /**\n * Gets the locales supported by the underlying recognizer.\n *\n * Android 13+ devices no longer expose this list; in that case `languages` is empty.\n */\n getSupportedLanguages(): Promise<SpeechRecognitionLanguages>;\n /**\n * Returns whether the plugin is actively listening for speech.\n */\n isListening(): Promise<SpeechRecognitionListening>;\n /**\n * Gets the current permission state.\n */\n checkPermissions(): Promise<SpeechRecognitionPermissionStatus>;\n /**\n * Requests the microphone + speech recognition permissions.\n */\n requestPermissions(): Promise<SpeechRecognitionPermissionStatus>;\n /**\n * Returns the native plugin version bundled with this package.\n *\n * Useful when reporting issues to confirm that native and JS versions match.\n */\n getPluginVersion(): Promise<{ version: string }>;\n /**\n * Listen for segmented session completion events (Android only).\n */\n addListener(eventName: 'endOfSegmentedSession', listenerFunc: () => void): Promise<PluginListenerHandle>;\n /**\n * Listen for segmented recognition results (Android only).\n */\n addListener(\n eventName: 'segmentResults',\n listenerFunc: (event: SpeechRecognitionSegmentResultEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Listen for partial transcription updates emitted while `partialResults` is enabled.\n */\n addListener(\n eventName: 'partialResults',\n listenerFunc: (event: SpeechRecognitionPartialResultEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Listen for changes to the native listening state.\n */\n addListener(\n eventName: 'listeningState',\n listenerFunc: (event: SpeechRecognitionListeningEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Listen for recognition errors.\n */\n addListener(\n eventName: 'error',\n listenerFunc: (event: SpeechRecognitionErrorEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Listen for the recognizer becoming ready for another session.\n */\n addListener(\n eventName: 'readyForNextSession',\n listenerFunc: (event: SpeechRecognitionReadyEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Removes every registered listener.\n */\n removeAllListeners(): Promise<void>;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-speech-recognition",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.8",
|
|
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",
|