capacitor-microphone 0.0.17 → 0.0.19
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 +24 -14
- package/android/src/main/java/com/eddieagvictoria/capacitor_microphone/CapacitorMicrophonePlugin.java +46 -2
- package/dist/docs.json +41 -24
- package/dist/esm/definitions.d.ts +3 -4
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +5 -5
- package/dist/esm/web.js +30 -30
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +30 -30
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +30 -30
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/capacitor_microphonePlugin/CapacitorMicrophonePlugin.swift +27 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ npx cap sync
|
|
|
20
20
|
* [`stopListening()`](#stoplistening)
|
|
21
21
|
* [`addListener('partialResult', ...)`](#addlistenerpartialresult-)
|
|
22
22
|
* [`removeAllListeners()`](#removealllisteners)
|
|
23
|
+
* [`restartListening(...)`](#restartlistening)
|
|
23
24
|
* [Interfaces](#interfaces)
|
|
24
25
|
|
|
25
26
|
</docgen-index>
|
|
@@ -63,26 +64,22 @@ checkRequestPermission() => Promise<MicrophonePermissions>
|
|
|
63
64
|
### startListening(...)
|
|
64
65
|
|
|
65
66
|
```typescript
|
|
66
|
-
startListening(options?: StartListeningOptions | undefined) => Promise<
|
|
67
|
+
startListening(options?: StartListeningOptions | undefined) => Promise<void>
|
|
67
68
|
```
|
|
68
69
|
|
|
69
70
|
| Param | Type |
|
|
70
71
|
| ------------- | ----------------------------------------------------------------------- |
|
|
71
72
|
| **`options`** | <code><a href="#startlisteningoptions">StartListeningOptions</a></code> |
|
|
72
73
|
|
|
73
|
-
**Returns:** <code>Promise<<a href="#speechresult">SpeechResult</a>></code>
|
|
74
|
-
|
|
75
74
|
--------------------
|
|
76
75
|
|
|
77
76
|
|
|
78
77
|
### stopListening()
|
|
79
78
|
|
|
80
79
|
```typescript
|
|
81
|
-
stopListening() => Promise<
|
|
80
|
+
stopListening() => Promise<void>
|
|
82
81
|
```
|
|
83
82
|
|
|
84
|
-
**Returns:** <code>Promise<{ stopped: boolean; }></code>
|
|
85
|
-
|
|
86
83
|
--------------------
|
|
87
84
|
|
|
88
85
|
|
|
@@ -111,6 +108,19 @@ removeAllListeners() => Promise<void>
|
|
|
111
108
|
--------------------
|
|
112
109
|
|
|
113
110
|
|
|
111
|
+
### restartListening(...)
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
restartListening(options?: StartListeningOptions | undefined) => Promise<void>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
| Param | Type |
|
|
118
|
+
| ------------- | ----------------------------------------------------------------------- |
|
|
119
|
+
| **`options`** | <code><a href="#startlisteningoptions">StartListeningOptions</a></code> |
|
|
120
|
+
|
|
121
|
+
--------------------
|
|
122
|
+
|
|
123
|
+
|
|
114
124
|
### Interfaces
|
|
115
125
|
|
|
116
126
|
|
|
@@ -124,14 +134,6 @@ removeAllListeners() => Promise<void>
|
|
|
124
134
|
| **`errorMessage`** | <code>string</code> |
|
|
125
135
|
|
|
126
136
|
|
|
127
|
-
#### SpeechResult
|
|
128
|
-
|
|
129
|
-
| Prop | Type |
|
|
130
|
-
| ------------- | -------------------- |
|
|
131
|
-
| **`text`** | <code>string</code> |
|
|
132
|
-
| **`isFinal`** | <code>boolean</code> |
|
|
133
|
-
|
|
134
|
-
|
|
135
137
|
#### StartListeningOptions
|
|
136
138
|
|
|
137
139
|
| Prop | Type |
|
|
@@ -145,4 +147,12 @@ removeAllListeners() => Promise<void>
|
|
|
145
147
|
| ------------ | ----------------------------------------- |
|
|
146
148
|
| **`remove`** | <code>() => Promise<void></code> |
|
|
147
149
|
|
|
150
|
+
|
|
151
|
+
#### SpeechResult
|
|
152
|
+
|
|
153
|
+
| Prop | Type |
|
|
154
|
+
| ------------- | -------------------- |
|
|
155
|
+
| **`text`** | <code>string</code> |
|
|
156
|
+
| **`isFinal`** | <code>boolean</code> |
|
|
157
|
+
|
|
148
158
|
</docgen-api>
|
|
@@ -168,6 +168,13 @@ private void startListeningInternal(PluginCall call, String lang) {
|
|
|
168
168
|
stopSpeech();
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
notifyListeners(
|
|
172
|
+
"partialResult",
|
|
173
|
+
new JSObject()
|
|
174
|
+
.put("text", "")
|
|
175
|
+
.put("isFinal", true)
|
|
176
|
+
);
|
|
177
|
+
|
|
171
178
|
this.currentCall = call;
|
|
172
179
|
|
|
173
180
|
getActivity().runOnUiThread(() -> {
|
|
@@ -189,7 +196,10 @@ private void startListeningInternal(PluginCall call, String lang) {
|
|
|
189
196
|
error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT) {
|
|
190
197
|
|
|
191
198
|
if (!isDestroyed && isListening && speechRecognizer != null) {
|
|
192
|
-
|
|
199
|
+
if (speechIntent != null) {
|
|
200
|
+
speechRecognizer.startListening(speechIntent);
|
|
201
|
+
}
|
|
202
|
+
|
|
193
203
|
}
|
|
194
204
|
return;
|
|
195
205
|
}
|
|
@@ -214,9 +224,10 @@ private void startListeningInternal(PluginCall call, String lang) {
|
|
|
214
224
|
);
|
|
215
225
|
}
|
|
216
226
|
|
|
217
|
-
if (!isDestroyed && isListening && speechRecognizer != null) {
|
|
227
|
+
if (!isDestroyed && isListening && speechRecognizer != null && speechIntent != null) {
|
|
218
228
|
speechRecognizer.startListening(speechIntent);
|
|
219
229
|
}
|
|
230
|
+
|
|
220
231
|
}
|
|
221
232
|
|
|
222
233
|
@Override
|
|
@@ -293,6 +304,39 @@ private void startListeningInternal(PluginCall call, String lang) {
|
|
|
293
304
|
} catch (Exception ignored) {}
|
|
294
305
|
}
|
|
295
306
|
|
|
307
|
+
@PluginMethod
|
|
308
|
+
public void restartListening(PluginCall call) {
|
|
309
|
+
String lang = call.getString("lang", "es-MX");
|
|
310
|
+
|
|
311
|
+
isListening = false;
|
|
312
|
+
isDestroyed = true;
|
|
313
|
+
|
|
314
|
+
if (delayedStartRunnable != null) {
|
|
315
|
+
getActivity().runOnUiThread(() -> {
|
|
316
|
+
getActivity()
|
|
317
|
+
.getWindow()
|
|
318
|
+
.getDecorView()
|
|
319
|
+
.removeCallbacks(delayedStartRunnable);
|
|
320
|
+
});
|
|
321
|
+
delayedStartRunnable = null;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
stopSpeech();
|
|
325
|
+
|
|
326
|
+
getActivity().runOnUiThread(() -> {
|
|
327
|
+
getActivity()
|
|
328
|
+
.getWindow()
|
|
329
|
+
.getDecorView()
|
|
330
|
+
.postDelayed(() -> {
|
|
331
|
+
isDestroyed = false;
|
|
332
|
+
isListening = true;
|
|
333
|
+
speechIntent = null;
|
|
334
|
+
startListeningInternal(call, lang);
|
|
335
|
+
}, 250);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
call.resolve();
|
|
339
|
+
}
|
|
296
340
|
|
|
297
341
|
|
|
298
342
|
|
package/dist/docs.json
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
"name": "startListening",
|
|
46
|
-
"signature": "(options?: StartListeningOptions | undefined) => Promise<
|
|
46
|
+
"signature": "(options?: StartListeningOptions | undefined) => Promise<void>",
|
|
47
47
|
"parameters": [
|
|
48
48
|
{
|
|
49
49
|
"name": "options",
|
|
@@ -51,20 +51,19 @@
|
|
|
51
51
|
"type": "StartListeningOptions | undefined"
|
|
52
52
|
}
|
|
53
53
|
],
|
|
54
|
-
"returns": "Promise<
|
|
54
|
+
"returns": "Promise<void>",
|
|
55
55
|
"tags": [],
|
|
56
56
|
"docs": "",
|
|
57
57
|
"complexTypes": [
|
|
58
|
-
"SpeechResult",
|
|
59
58
|
"StartListeningOptions"
|
|
60
59
|
],
|
|
61
60
|
"slug": "startlistening"
|
|
62
61
|
},
|
|
63
62
|
{
|
|
64
63
|
"name": "stopListening",
|
|
65
|
-
"signature": "() => Promise<
|
|
64
|
+
"signature": "() => Promise<void>",
|
|
66
65
|
"parameters": [],
|
|
67
|
-
"returns": "Promise<
|
|
66
|
+
"returns": "Promise<void>",
|
|
68
67
|
"tags": [],
|
|
69
68
|
"docs": "",
|
|
70
69
|
"complexTypes": [],
|
|
@@ -103,6 +102,24 @@
|
|
|
103
102
|
"docs": "",
|
|
104
103
|
"complexTypes": [],
|
|
105
104
|
"slug": "removealllisteners"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "restartListening",
|
|
108
|
+
"signature": "(options?: StartListeningOptions | undefined) => Promise<void>",
|
|
109
|
+
"parameters": [
|
|
110
|
+
{
|
|
111
|
+
"name": "options",
|
|
112
|
+
"docs": "",
|
|
113
|
+
"type": "StartListeningOptions | undefined"
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"returns": "Promise<void>",
|
|
117
|
+
"tags": [],
|
|
118
|
+
"docs": "",
|
|
119
|
+
"complexTypes": [
|
|
120
|
+
"StartListeningOptions"
|
|
121
|
+
],
|
|
122
|
+
"slug": "restartlistening"
|
|
106
123
|
}
|
|
107
124
|
],
|
|
108
125
|
"properties": []
|
|
@@ -146,57 +163,57 @@
|
|
|
146
163
|
]
|
|
147
164
|
},
|
|
148
165
|
{
|
|
149
|
-
"name": "
|
|
150
|
-
"slug": "
|
|
166
|
+
"name": "StartListeningOptions",
|
|
167
|
+
"slug": "startlisteningoptions",
|
|
151
168
|
"docs": "",
|
|
152
169
|
"tags": [],
|
|
153
170
|
"methods": [],
|
|
154
171
|
"properties": [
|
|
155
172
|
{
|
|
156
|
-
"name": "
|
|
157
|
-
"tags": [],
|
|
158
|
-
"docs": "",
|
|
159
|
-
"complexTypes": [],
|
|
160
|
-
"type": "string"
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
"name": "isFinal",
|
|
173
|
+
"name": "lang",
|
|
164
174
|
"tags": [],
|
|
165
175
|
"docs": "",
|
|
166
176
|
"complexTypes": [],
|
|
167
|
-
"type": "
|
|
177
|
+
"type": "string | undefined"
|
|
168
178
|
}
|
|
169
179
|
]
|
|
170
180
|
},
|
|
171
181
|
{
|
|
172
|
-
"name": "
|
|
173
|
-
"slug": "
|
|
182
|
+
"name": "PluginListenerHandle",
|
|
183
|
+
"slug": "pluginlistenerhandle",
|
|
174
184
|
"docs": "",
|
|
175
185
|
"tags": [],
|
|
176
186
|
"methods": [],
|
|
177
187
|
"properties": [
|
|
178
188
|
{
|
|
179
|
-
"name": "
|
|
189
|
+
"name": "remove",
|
|
180
190
|
"tags": [],
|
|
181
191
|
"docs": "",
|
|
182
192
|
"complexTypes": [],
|
|
183
|
-
"type": "
|
|
193
|
+
"type": "() => Promise<void>"
|
|
184
194
|
}
|
|
185
195
|
]
|
|
186
196
|
},
|
|
187
197
|
{
|
|
188
|
-
"name": "
|
|
189
|
-
"slug": "
|
|
198
|
+
"name": "SpeechResult",
|
|
199
|
+
"slug": "speechresult",
|
|
190
200
|
"docs": "",
|
|
191
201
|
"tags": [],
|
|
192
202
|
"methods": [],
|
|
193
203
|
"properties": [
|
|
194
204
|
{
|
|
195
|
-
"name": "
|
|
205
|
+
"name": "text",
|
|
196
206
|
"tags": [],
|
|
197
207
|
"docs": "",
|
|
198
208
|
"complexTypes": [],
|
|
199
|
-
"type": "
|
|
209
|
+
"type": "string"
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"name": "isFinal",
|
|
213
|
+
"tags": [],
|
|
214
|
+
"docs": "",
|
|
215
|
+
"complexTypes": [],
|
|
216
|
+
"type": "boolean"
|
|
200
217
|
}
|
|
201
218
|
]
|
|
202
219
|
}
|
|
@@ -3,12 +3,11 @@ export interface CapacitorMicrophonePlugin {
|
|
|
3
3
|
checkPermission(): Promise<MicrophonePermissions>;
|
|
4
4
|
requestPermission(): Promise<MicrophonePermissions>;
|
|
5
5
|
checkRequestPermission(): Promise<MicrophonePermissions>;
|
|
6
|
-
startListening(options?: StartListeningOptions): Promise<
|
|
7
|
-
stopListening(): Promise<
|
|
8
|
-
stopped: boolean;
|
|
9
|
-
}>;
|
|
6
|
+
startListening(options?: StartListeningOptions): Promise<void>;
|
|
7
|
+
stopListening(): Promise<void>;
|
|
10
8
|
addListener(eventName: 'partialResult', listenerFunc: (data: SpeechResult) => void): Promise<PluginListenerHandle>;
|
|
11
9
|
removeAllListeners(): Promise<void>;
|
|
10
|
+
restartListening(options?: StartListeningOptions): Promise<void>;
|
|
12
11
|
}
|
|
13
12
|
export interface MicrophonePermissions {
|
|
14
13
|
details: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface CapacitorMicrophonePlugin {\n checkPermission(): Promise<MicrophonePermissions>;\n requestPermission(): Promise<MicrophonePermissions>;\n checkRequestPermission(): Promise<MicrophonePermissions>;\n startListening(options?: StartListeningOptions): Promise<
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface CapacitorMicrophonePlugin {\n checkPermission(): Promise<MicrophonePermissions>;\n requestPermission(): Promise<MicrophonePermissions>;\n checkRequestPermission(): Promise<MicrophonePermissions>;\n startListening(options?: StartListeningOptions): Promise<void>;\n stopListening(): Promise<void>;\n addListener(eventName: 'partialResult', listenerFunc: (data: SpeechResult) => void): Promise<PluginListenerHandle>;\n removeAllListeners(): Promise<void>;\n restartListening(options?: StartListeningOptions): Promise<void>;\n}\n\nexport interface MicrophonePermissions {\n details: string;\n granted: boolean;\n status:string;\n errorMessage: string;\n}\n\nexport interface StartListeningOptions {\n lang?: string; //'es-MX', 'en-US'\n}\n\nexport interface SpeechResult {\n text: string;\n isFinal: boolean;\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type { CapacitorMicrophonePlugin, MicrophonePermissions,
|
|
2
|
+
import type { CapacitorMicrophonePlugin, MicrophonePermissions, StartListeningOptions } from './definitions';
|
|
3
3
|
export declare class CapacitorMicrophoneWeb extends WebPlugin implements CapacitorMicrophonePlugin {
|
|
4
4
|
private recognition;
|
|
5
|
+
private currentLang;
|
|
5
6
|
checkPermission(): Promise<MicrophonePermissions>;
|
|
6
7
|
requestPermission(): Promise<MicrophonePermissions>;
|
|
7
8
|
checkRequestPermission(): Promise<MicrophonePermissions>;
|
|
8
|
-
startListening(options?: StartListeningOptions): Promise<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}>;
|
|
9
|
+
startListening(options?: StartListeningOptions): Promise<void>;
|
|
10
|
+
restartListening(options?: StartListeningOptions): Promise<void>;
|
|
11
|
+
stopListening(): Promise<void>;
|
|
12
12
|
private stopRecognition;
|
|
13
13
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -3,6 +3,7 @@ export class CapacitorMicrophoneWeb extends WebPlugin {
|
|
|
3
3
|
constructor() {
|
|
4
4
|
super(...arguments);
|
|
5
5
|
this.recognition = null;
|
|
6
|
+
this.currentLang = 'es-MX';
|
|
6
7
|
}
|
|
7
8
|
async checkPermission() {
|
|
8
9
|
var _a;
|
|
@@ -56,9 +57,8 @@ export class CapacitorMicrophoneWeb extends WebPlugin {
|
|
|
56
57
|
}
|
|
57
58
|
async checkRequestPermission() {
|
|
58
59
|
const permission = await this.checkPermission();
|
|
59
|
-
if (permission.granted)
|
|
60
|
+
if (permission.granted)
|
|
60
61
|
return permission;
|
|
61
|
-
}
|
|
62
62
|
return this.requestPermission();
|
|
63
63
|
}
|
|
64
64
|
async startListening(options) {
|
|
@@ -67,42 +67,42 @@ export class CapacitorMicrophoneWeb extends WebPlugin {
|
|
|
67
67
|
if (!SpeechRecognition) {
|
|
68
68
|
throw new Error('Speech recognition not supported in this browser');
|
|
69
69
|
}
|
|
70
|
-
if (this.recognition)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const lang = (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'es-MX';
|
|
70
|
+
if (this.recognition)
|
|
71
|
+
return;
|
|
72
|
+
this.currentLang = (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'es-MX';
|
|
74
73
|
this.recognition = new SpeechRecognition();
|
|
75
|
-
this.recognition.lang =
|
|
74
|
+
this.recognition.lang = this.currentLang;
|
|
76
75
|
this.recognition.interimResults = true;
|
|
77
|
-
this.recognition.continuous =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
this.recognition.start();
|
|
97
|
-
});
|
|
76
|
+
this.recognition.continuous = true;
|
|
77
|
+
this.recognition.onresult = (event) => {
|
|
78
|
+
const result = event.results[event.results.length - 1];
|
|
79
|
+
const text = result[0].transcript;
|
|
80
|
+
const isFinal = result.isFinal;
|
|
81
|
+
this.notifyListeners('partialResult', {
|
|
82
|
+
text,
|
|
83
|
+
isFinal,
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
this.recognition.onerror = () => {
|
|
87
|
+
this.restartListening({ lang: this.currentLang });
|
|
88
|
+
};
|
|
89
|
+
this.recognition.start();
|
|
90
|
+
}
|
|
91
|
+
async restartListening(options) {
|
|
92
|
+
this.stopRecognition();
|
|
93
|
+
await this.startListening(options);
|
|
98
94
|
}
|
|
99
95
|
async stopListening() {
|
|
100
96
|
this.stopRecognition();
|
|
101
|
-
return { stopped: true };
|
|
102
97
|
}
|
|
103
98
|
stopRecognition() {
|
|
104
99
|
if (this.recognition) {
|
|
105
|
-
|
|
100
|
+
try {
|
|
101
|
+
this.recognition.stop();
|
|
102
|
+
}
|
|
103
|
+
catch (_a) {
|
|
104
|
+
// ignore
|
|
105
|
+
}
|
|
106
106
|
this.recognition = null;
|
|
107
107
|
}
|
|
108
108
|
}
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,MAAM,OAAO,sBAAuB,SAAQ,SAAS;IAArD;;QACU,gBAAW,GAAQ,IAAI,CAAC;QACxB,gBAAW,GAAG,OAAO,CAAC;IAgHhC,CAAC;IA9GC,KAAK,CAAC,eAAe;;QACnB,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;YAC3B,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,QAAQ;gBAChB,OAAO,EAAE,+BAA+B;gBACxC,YAAY,EAAE,EAAE;aACjB,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;gBAC/C,IAAI,EAAE,YAAmB;aAC1B,CAAC,CAAC;YAEH,OAAO;gBACL,OAAO,EAAE,MAAM,CAAC,KAAK,KAAK,SAAS;gBACnC,MAAM,EAAE,MAAM,CAAC,KAAY;gBAC3B,OAAO,EAAE,qBAAqB;gBAC9B,YAAY,EAAE,EAAE;aACjB,CAAC;QACJ,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,QAAQ;gBAChB,OAAO,EAAE,2BAA2B;g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CAAC;IACH,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CapacitorMicrophonePlugin,\n MicrophonePermissions,\n StartListeningOptions,\n} from './definitions';\n\nexport class CapacitorMicrophoneWeb extends WebPlugin implements CapacitorMicrophonePlugin {\n private recognition: any = null;\n private currentLang = 'es-MX';\n\n async checkPermission(): Promise<MicrophonePermissions> {\n if (!navigator.permissions) {\n return {\n granted: false,\n status: 'prompt',\n details: 'Permissions API not supported',\n errorMessage: '',\n };\n }\n\n try {\n const result = await navigator.permissions.query({\n name: 'microphone' as any,\n });\n\n return {\n granted: result.state === 'granted',\n status: result.state as any,\n details: 'Web checkPermission',\n errorMessage: '',\n };\n } catch (err: any) {\n return {\n granted: false,\n status: 'denied',\n details: 'Web checkPermission error',\n errorMessage: err?.message ?? 'Unknown error',\n };\n }\n }\n\n async requestPermission(): Promise<MicrophonePermissions> {\n try {\n await navigator.mediaDevices.getUserMedia({ audio: true });\n\n return {\n granted: true,\n status: 'granted',\n details: 'Web requestPermission',\n errorMessage: '',\n };\n } catch (err: any) {\n return {\n granted: false,\n status: 'denied',\n details: 'Web requestPermission',\n errorMessage: err?.message ?? 'User denied microphone permission',\n };\n }\n }\n\n async checkRequestPermission(): Promise<MicrophonePermissions> {\n const permission = await this.checkPermission();\n if (permission.granted) return permission;\n return this.requestPermission();\n }\n\n async startListening(options?: StartListeningOptions): Promise<void> {\n const SpeechRecognition = (window as any).SpeechRecognition || (window as any).webkitSpeechRecognition;\n\n if (!SpeechRecognition) {\n throw new Error('Speech recognition not supported in this browser');\n }\n\n if (this.recognition) return;\n\n this.currentLang = options?.lang ?? 'es-MX';\n\n this.recognition = new SpeechRecognition();\n this.recognition.lang = this.currentLang;\n this.recognition.interimResults = true;\n this.recognition.continuous = true;\n\n this.recognition.onresult = (event: any) => {\n const result = event.results[event.results.length - 1];\n const text = result[0].transcript;\n const isFinal = result.isFinal;\n\n this.notifyListeners('partialResult', {\n text,\n isFinal,\n });\n };\n\n this.recognition.onerror = () => {\n this.restartListening({ lang: this.currentLang });\n };\n\n this.recognition.start();\n }\n\n async restartListening(options?: StartListeningOptions): Promise<void> {\n this.stopRecognition();\n await this.startListening(options);\n }\n\n async stopListening(): Promise<void> {\n this.stopRecognition();\n }\n\n private stopRecognition() {\n if (this.recognition) {\n try {\n this.recognition.stop();\n } catch {\n // ignore\n }\n this.recognition = null;\n }\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -10,6 +10,7 @@ class CapacitorMicrophoneWeb extends core.WebPlugin {
|
|
|
10
10
|
constructor() {
|
|
11
11
|
super(...arguments);
|
|
12
12
|
this.recognition = null;
|
|
13
|
+
this.currentLang = 'es-MX';
|
|
13
14
|
}
|
|
14
15
|
async checkPermission() {
|
|
15
16
|
var _a;
|
|
@@ -63,9 +64,8 @@ class CapacitorMicrophoneWeb extends core.WebPlugin {
|
|
|
63
64
|
}
|
|
64
65
|
async checkRequestPermission() {
|
|
65
66
|
const permission = await this.checkPermission();
|
|
66
|
-
if (permission.granted)
|
|
67
|
+
if (permission.granted)
|
|
67
68
|
return permission;
|
|
68
|
-
}
|
|
69
69
|
return this.requestPermission();
|
|
70
70
|
}
|
|
71
71
|
async startListening(options) {
|
|
@@ -74,42 +74,42 @@ class CapacitorMicrophoneWeb extends core.WebPlugin {
|
|
|
74
74
|
if (!SpeechRecognition) {
|
|
75
75
|
throw new Error('Speech recognition not supported in this browser');
|
|
76
76
|
}
|
|
77
|
-
if (this.recognition)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const lang = (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'es-MX';
|
|
77
|
+
if (this.recognition)
|
|
78
|
+
return;
|
|
79
|
+
this.currentLang = (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'es-MX';
|
|
81
80
|
this.recognition = new SpeechRecognition();
|
|
82
|
-
this.recognition.lang =
|
|
81
|
+
this.recognition.lang = this.currentLang;
|
|
83
82
|
this.recognition.interimResults = true;
|
|
84
|
-
this.recognition.continuous =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
};
|
|
103
|
-
this.recognition.start();
|
|
104
|
-
});
|
|
83
|
+
this.recognition.continuous = true;
|
|
84
|
+
this.recognition.onresult = (event) => {
|
|
85
|
+
const result = event.results[event.results.length - 1];
|
|
86
|
+
const text = result[0].transcript;
|
|
87
|
+
const isFinal = result.isFinal;
|
|
88
|
+
this.notifyListeners('partialResult', {
|
|
89
|
+
text,
|
|
90
|
+
isFinal,
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
this.recognition.onerror = () => {
|
|
94
|
+
this.restartListening({ lang: this.currentLang });
|
|
95
|
+
};
|
|
96
|
+
this.recognition.start();
|
|
97
|
+
}
|
|
98
|
+
async restartListening(options) {
|
|
99
|
+
this.stopRecognition();
|
|
100
|
+
await this.startListening(options);
|
|
105
101
|
}
|
|
106
102
|
async stopListening() {
|
|
107
103
|
this.stopRecognition();
|
|
108
|
-
return { stopped: true };
|
|
109
104
|
}
|
|
110
105
|
stopRecognition() {
|
|
111
106
|
if (this.recognition) {
|
|
112
|
-
|
|
107
|
+
try {
|
|
108
|
+
this.recognition.stop();
|
|
109
|
+
}
|
|
110
|
+
catch (_a) {
|
|
111
|
+
// ignore
|
|
112
|
+
}
|
|
113
113
|
this.recognition = null;
|
|
114
114
|
}
|
|
115
115
|
}
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst capacitor_microphone = registerPlugin('CapacitorMicrophone', {\n web: () => import('./web').then((m) => new m.CapacitorMicrophoneWeb()),\n});\nexport * from './definitions';\nexport { capacitor_microphone };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorMicrophoneWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.recognition = null;\n }\n async checkPermission() {\n var _a;\n if (!navigator.permissions) {\n return {\n granted: false,\n status: 'prompt',\n details: 'Permissions API not supported',\n errorMessage: '',\n };\n }\n try {\n const result = await navigator.permissions.query({\n name: 'microphone',\n });\n return {\n granted: result.state === 'granted',\n status: result.state,\n details: 'Web checkPermission',\n errorMessage: '',\n };\n }\n catch (err) {\n return {\n granted: false,\n status: 'denied',\n details: 'Web checkPermission error',\n errorMessage: (_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'Unknown error',\n };\n }\n }\n async requestPermission() {\n var _a;\n try {\n await navigator.mediaDevices.getUserMedia({ audio: true });\n return {\n granted: true,\n status: 'granted',\n details: 'Web requestPermission',\n errorMessage: '',\n };\n }\n catch (err) {\n return {\n granted: false,\n status: 'denied',\n details: 'Web requestPermission',\n errorMessage: (_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'User denied microphone permission',\n };\n }\n }\n async checkRequestPermission() {\n const permission = await this.checkPermission();\n if (permission.granted)
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst capacitor_microphone = registerPlugin('CapacitorMicrophone', {\n web: () => import('./web').then((m) => new m.CapacitorMicrophoneWeb()),\n});\nexport * from './definitions';\nexport { capacitor_microphone };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorMicrophoneWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.recognition = null;\n this.currentLang = 'es-MX';\n }\n async checkPermission() {\n var _a;\n if (!navigator.permissions) {\n return {\n granted: false,\n status: 'prompt',\n details: 'Permissions API not supported',\n errorMessage: '',\n };\n }\n try {\n const result = await navigator.permissions.query({\n name: 'microphone',\n });\n return {\n granted: result.state === 'granted',\n status: result.state,\n details: 'Web checkPermission',\n errorMessage: '',\n };\n }\n catch (err) {\n return {\n granted: false,\n status: 'denied',\n details: 'Web checkPermission error',\n errorMessage: (_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'Unknown error',\n };\n }\n }\n async requestPermission() {\n var _a;\n try {\n await navigator.mediaDevices.getUserMedia({ audio: true });\n return {\n granted: true,\n status: 'granted',\n details: 'Web requestPermission',\n errorMessage: '',\n };\n }\n catch (err) {\n return {\n granted: false,\n status: 'denied',\n details: 'Web requestPermission',\n errorMessage: (_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'User denied microphone permission',\n };\n }\n }\n async checkRequestPermission() {\n const permission = await this.checkPermission();\n if (permission.granted)\n return permission;\n return this.requestPermission();\n }\n async startListening(options) {\n var _a;\n const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;\n if (!SpeechRecognition) {\n throw new Error('Speech recognition not supported in this browser');\n }\n if (this.recognition)\n return;\n this.currentLang = (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'es-MX';\n this.recognition = new SpeechRecognition();\n this.recognition.lang = this.currentLang;\n this.recognition.interimResults = true;\n this.recognition.continuous = true;\n this.recognition.onresult = (event) => {\n const result = event.results[event.results.length - 1];\n const text = result[0].transcript;\n const isFinal = result.isFinal;\n this.notifyListeners('partialResult', {\n text,\n isFinal,\n });\n };\n this.recognition.onerror = () => {\n this.restartListening({ lang: this.currentLang });\n };\n this.recognition.start();\n }\n async restartListening(options) {\n this.stopRecognition();\n await this.startListening(options);\n }\n async stopListening() {\n this.stopRecognition();\n }\n stopRecognition() {\n if (this.recognition) {\n try {\n this.recognition.stop();\n }\n catch (_a) {\n // ignore\n }\n this.recognition = null;\n }\n }\n}\n//# sour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I,CAAC,WAAW,CAAC,KAAK,EAAE;AAChC,IAAI;AACJ,IAAI,MAAM,gBAAgB,CAAC,OAAO,EAAE;AACpC,QAAQ,IAAI,CAAC,eAAe,EAAE;AAC9B,QAAQ,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;AAC1C,IAAI;AACJ,IAAI,MAAM,aAAa,GAAG;AAC1B,QAAQ,IAAI,CAAC,eAAe,EAAE;AAC9B,IAAI;AACJ,IAAI,eAAe,GAAG;AACtB,QAAQ,IAAI,IAAI,CAAC,WAAW,EAAE;AAC9B,YAAY,IAAI;AAChB,gBAAgB,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE;AACvC,YAAY;AACZ,YAAY,OAAO,EAAE,EAAE;AACvB;AACA,YAAY;AACZ,YAAY,IAAI,CAAC,WAAW,GAAG,IAAI;AACnC,QAAQ;AACR,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -9,6 +9,7 @@ var capacitorcapacitor_microphone = (function (exports, core) {
|
|
|
9
9
|
constructor() {
|
|
10
10
|
super(...arguments);
|
|
11
11
|
this.recognition = null;
|
|
12
|
+
this.currentLang = 'es-MX';
|
|
12
13
|
}
|
|
13
14
|
async checkPermission() {
|
|
14
15
|
var _a;
|
|
@@ -62,9 +63,8 @@ var capacitorcapacitor_microphone = (function (exports, core) {
|
|
|
62
63
|
}
|
|
63
64
|
async checkRequestPermission() {
|
|
64
65
|
const permission = await this.checkPermission();
|
|
65
|
-
if (permission.granted)
|
|
66
|
+
if (permission.granted)
|
|
66
67
|
return permission;
|
|
67
|
-
}
|
|
68
68
|
return this.requestPermission();
|
|
69
69
|
}
|
|
70
70
|
async startListening(options) {
|
|
@@ -73,42 +73,42 @@ var capacitorcapacitor_microphone = (function (exports, core) {
|
|
|
73
73
|
if (!SpeechRecognition) {
|
|
74
74
|
throw new Error('Speech recognition not supported in this browser');
|
|
75
75
|
}
|
|
76
|
-
if (this.recognition)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const lang = (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'es-MX';
|
|
76
|
+
if (this.recognition)
|
|
77
|
+
return;
|
|
78
|
+
this.currentLang = (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'es-MX';
|
|
80
79
|
this.recognition = new SpeechRecognition();
|
|
81
|
-
this.recognition.lang =
|
|
80
|
+
this.recognition.lang = this.currentLang;
|
|
82
81
|
this.recognition.interimResults = true;
|
|
83
|
-
this.recognition.continuous =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
};
|
|
102
|
-
this.recognition.start();
|
|
103
|
-
});
|
|
82
|
+
this.recognition.continuous = true;
|
|
83
|
+
this.recognition.onresult = (event) => {
|
|
84
|
+
const result = event.results[event.results.length - 1];
|
|
85
|
+
const text = result[0].transcript;
|
|
86
|
+
const isFinal = result.isFinal;
|
|
87
|
+
this.notifyListeners('partialResult', {
|
|
88
|
+
text,
|
|
89
|
+
isFinal,
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
this.recognition.onerror = () => {
|
|
93
|
+
this.restartListening({ lang: this.currentLang });
|
|
94
|
+
};
|
|
95
|
+
this.recognition.start();
|
|
96
|
+
}
|
|
97
|
+
async restartListening(options) {
|
|
98
|
+
this.stopRecognition();
|
|
99
|
+
await this.startListening(options);
|
|
104
100
|
}
|
|
105
101
|
async stopListening() {
|
|
106
102
|
this.stopRecognition();
|
|
107
|
-
return { stopped: true };
|
|
108
103
|
}
|
|
109
104
|
stopRecognition() {
|
|
110
105
|
if (this.recognition) {
|
|
111
|
-
|
|
106
|
+
try {
|
|
107
|
+
this.recognition.stop();
|
|
108
|
+
}
|
|
109
|
+
catch (_a) {
|
|
110
|
+
// ignore
|
|
111
|
+
}
|
|
112
112
|
this.recognition = null;
|
|
113
113
|
}
|
|
114
114
|
}
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst capacitor_microphone = registerPlugin('CapacitorMicrophone', {\n web: () => import('./web').then((m) => new m.CapacitorMicrophoneWeb()),\n});\nexport * from './definitions';\nexport { capacitor_microphone };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorMicrophoneWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.recognition = null;\n }\n async checkPermission() {\n var _a;\n if (!navigator.permissions) {\n return {\n granted: false,\n status: 'prompt',\n details: 'Permissions API not supported',\n errorMessage: '',\n };\n }\n try {\n const result = await navigator.permissions.query({\n name: 'microphone',\n });\n return {\n granted: result.state === 'granted',\n status: result.state,\n details: 'Web checkPermission',\n errorMessage: '',\n };\n }\n catch (err) {\n return {\n granted: false,\n status: 'denied',\n details: 'Web checkPermission error',\n errorMessage: (_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'Unknown error',\n };\n }\n }\n async requestPermission() {\n var _a;\n try {\n await navigator.mediaDevices.getUserMedia({ audio: true });\n return {\n granted: true,\n status: 'granted',\n details: 'Web requestPermission',\n errorMessage: '',\n };\n }\n catch (err) {\n return {\n granted: false,\n status: 'denied',\n details: 'Web requestPermission',\n errorMessage: (_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'User denied microphone permission',\n };\n }\n }\n async checkRequestPermission() {\n const permission = await this.checkPermission();\n if (permission.granted)
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst capacitor_microphone = registerPlugin('CapacitorMicrophone', {\n web: () => import('./web').then((m) => new m.CapacitorMicrophoneWeb()),\n});\nexport * from './definitions';\nexport { capacitor_microphone };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorMicrophoneWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.recognition = null;\n this.currentLang = 'es-MX';\n }\n async checkPermission() {\n var _a;\n if (!navigator.permissions) {\n return {\n granted: false,\n status: 'prompt',\n details: 'Permissions API not supported',\n errorMessage: '',\n };\n }\n try {\n const result = await navigator.permissions.query({\n name: 'microphone',\n });\n return {\n granted: result.state === 'granted',\n status: result.state,\n details: 'Web checkPermission',\n errorMessage: '',\n };\n }\n catch (err) {\n return {\n granted: false,\n status: 'denied',\n details: 'Web checkPermission error',\n errorMessage: (_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'Unknown error',\n };\n }\n }\n async requestPermission() {\n var _a;\n try {\n await navigator.mediaDevices.getUserMedia({ audio: true });\n return {\n granted: true,\n status: 'granted',\n details: 'Web requestPermission',\n errorMessage: '',\n };\n }\n catch (err) {\n return {\n granted: false,\n status: 'denied',\n details: 'Web requestPermission',\n errorMessage: (_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'User denied microphone permission',\n };\n }\n }\n async checkRequestPermission() {\n const permission = await this.checkPermission();\n if (permission.granted)\n return permission;\n return this.requestPermission();\n }\n async startListening(options) {\n var _a;\n const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;\n if (!SpeechRecognition) {\n throw new Error('Speech recognition not supported in this browser');\n }\n if (this.recognition)\n return;\n this.currentLang = (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'es-MX';\n this.recognition = new SpeechRecognition();\n this.recognition.lang = this.currentLang;\n this.recognition.interimResults = true;\n this.recognition.continuous = true;\n this.recognition.onresult = (event) => {\n const result = event.results[event.results.length - 1];\n const text = result[0].transcript;\n const isFinal = result.isFinal;\n this.notifyListeners('partialResult', {\n text,\n isFinal,\n });\n };\n this.recognition.onerror = () => {\n this.restartListening({ lang: this.currentLang });\n };\n this.recognition.start();\n }\n async restartListening(options) {\n this.stopRecognition();\n await this.startListening(options);\n }\n async stopListening() {\n this.stopRecognition();\n }\n stopRecognition() {\n if (this.recognition) {\n try {\n this.recognition.stop();\n }\n catch (_a) {\n // ignore\n }\n this.recognition = null;\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,oBAAoB,GAAGA,mBAAc,CAAC,qBAAqB,EAAE;IACnE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,sBAAsB,EAAE,CAAC;IAC1E,CAAC;;ICFM,MAAM,sBAAsB,SAASC,cAAS,CAAC;IACtD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;IAC3B,QAAQ,IAAI,CAAC,WAAW,GAAG,IAAI;IAC/B,QAAQ,IAAI,CAAC,WAAW,GAAG,OAAO;IAClC,IAAI;IACJ,IAAI,MAAM,eAAe,GAAG;IAC5B,QAAQ,IAAI,EAAE;IACd,QAAQ,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;IACpC,YAAY,OAAO;IACnB,gBAAgB,OAAO,EAAE,KAAK;IAC9B,gBAAgB,MAAM,EAAE,QAAQ;IAChC,gBAAgB,OAAO,EAAE,+BAA+B;IACxD,gBAAgB,YAAY,EAAE,EAAE;IAChC,aAAa;IACb,QAAQ;IACR,QAAQ,IAAI;IACZ,YAAY,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;IAC7D,gBAAgB,IAAI,EAAE,YAAY;IAClC,aAAa,CAAC;IACd,YAAY,OAAO;IACnB,gBAAgB,OAAO,EAAE,MAAM,CAAC,KAAK,KAAK,SAAS;IACnD,gBAAgB,MAAM,EAAE,MA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C,eAAe,EAAE;IAClD,gBAAgB,IAAI;IACpB,gBAAgB,OAAO;IACvB,aAAa,CAAC;IACd,QAAQ,CAAC;IACT,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,GAAG,MAAM;IACzC,YAAY,IAAI,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;IAC7D,QAAQ,CAAC;IACT,QAAQ,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE;IAChC,IAAI;IACJ,IAAI,MAAM,gBAAgB,CAAC,OAAO,EAAE;IACpC,QAAQ,IAAI,CAAC,eAAe,EAAE;IAC9B,QAAQ,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;IAC1C,IAAI;IACJ,IAAI,MAAM,aAAa,GAAG;IAC1B,QAAQ,IAAI,CAAC,eAAe,EAAE;IAC9B,IAAI;IACJ,IAAI,eAAe,GAAG;IACtB,QAAQ,IAAI,IAAI,CAAC,WAAW,EAAE;IAC9B,YAAY,IAAI;IAChB,gBAAgB,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE;IACvC,YAAY;IACZ,YAAY,OAAO,EAAE,EAAE;IACvB;IACA,YAAY;IACZ,YAAY,IAAI,CAAC,WAAW,GAAG,IAAI;IACnC,QAAQ;IACR,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -12,7 +12,9 @@ public let identifier = "CapacitorMicrophone"
|
|
|
12
12
|
CAPPluginMethod(name: "requestPermission", returnType: CAPPluginReturnPromise),
|
|
13
13
|
CAPPluginMethod(name: "checkRequestPermission", returnType: CAPPluginReturnPromise),
|
|
14
14
|
CAPPluginMethod(name: "startListening", returnType: CAPPluginReturnPromise),
|
|
15
|
-
CAPPluginMethod(name: "stopListening", returnType: CAPPluginReturnPromise)
|
|
15
|
+
CAPPluginMethod(name: "stopListening", returnType: CAPPluginReturnPromise),
|
|
16
|
+
CAPPluginMethod(name: "restartListening", returnType: CAPPluginReturnPromise)
|
|
17
|
+
|
|
16
18
|
]
|
|
17
19
|
|
|
18
20
|
private var speechRecognizer: SFSpeechRecognizer?
|
|
@@ -352,6 +354,30 @@ public let identifier = "CapacitorMicrophone"
|
|
|
352
354
|
}
|
|
353
355
|
}
|
|
354
356
|
|
|
357
|
+
@objc func restartListening(_ call: CAPPluginCall) {
|
|
358
|
+
let lang = call.getString("lang") ?? "es-MX"
|
|
359
|
+
|
|
360
|
+
// Marcar como detenido
|
|
361
|
+
isListening = false
|
|
362
|
+
isDestroyed = true
|
|
363
|
+
|
|
364
|
+
delayedStartWorkItem?.cancel()
|
|
365
|
+
delayedStartWorkItem = nil
|
|
366
|
+
|
|
367
|
+
stopSpeech()
|
|
368
|
+
|
|
369
|
+
// Reiniciar limpio
|
|
370
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
|
|
371
|
+
self.isDestroyed = false
|
|
372
|
+
self.isListening = true
|
|
373
|
+
self.startListeningInternal(call: call, lang: lang)
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
call.resolve()
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
355
381
|
private func stopSpeech() {
|
|
356
382
|
lastStopTime = Date()
|
|
357
383
|
|