@capgo/capacitor-speech-recognition 7.0.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.
- package/CapgoCapacitorSpeechRecognition.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +360 -0
- package/android/build.gradle +57 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/app/capgo/speechrecognition/Constants.java +17 -0
- package/android/src/main/java/app/capgo/speechrecognition/Receiver.java +49 -0
- package/android/src/main/java/app/capgo/speechrecognition/SpeechRecognitionPlugin.java +406 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +438 -0
- package/dist/esm/definitions.d.ts +130 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +11 -0
- package/dist/esm/web.js +25 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +39 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +42 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/SpeechRecognitionPlugin/SpeechRecognitionPlugin.swift +282 -0
- package/ios/Tests/SpeechRecognitionPluginTests/SpeechRecognitionPluginTests.swift +7 -0
- package/package.json +87 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapgoCapacitorSpeechRecognition'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '14.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.9'
|
|
17
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Capgo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapgoCapacitorSpeechRecognition",
|
|
6
|
+
platforms: [.iOS(.v14)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapgoCapacitorSpeechRecognition",
|
|
10
|
+
targets: ["SpeechRecognitionPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "SpeechRecognitionPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Sources/SpeechRecognitionPlugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "SpeechRecognitionPluginTests",
|
|
25
|
+
dependencies: ["SpeechRecognitionPlugin"],
|
|
26
|
+
path: "ios/Tests/SpeechRecognitionPluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
# @capgo/capacitor-speech-recognition
|
|
2
|
+
<a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
|
|
3
|
+
|
|
4
|
+
<div align="center">
|
|
5
|
+
<h2><a href="https://capgo.app/?ref=plugin_speech_recognition"> ➡️ Get Instant updates for your App with Capgo</a></h2>
|
|
6
|
+
<h2><a href="https://capgo.app/consulting/?ref=plugin_speech_recognition"> Missing a feature? We’ll build the plugin for you 💪</a></h2>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
Natural, low-latency speech recognition for Capacitor apps with parity across iOS and Android, streaming partial results, and permission helpers baked in.
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
The most complete doc is available here: https://capgo.app/docs/plugins/speech-recognition/
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @capgo/capacitor-speech-recognition
|
|
19
|
+
npx cap sync
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
|
|
26
|
+
|
|
27
|
+
await SpeechRecognition.requestPermissions();
|
|
28
|
+
|
|
29
|
+
const { available } = await SpeechRecognition.available();
|
|
30
|
+
if (!available) {
|
|
31
|
+
console.warn('Speech recognition is not supported on this device.');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const partialListener = await SpeechRecognition.addListener('partialResults', (event) => {
|
|
35
|
+
console.log('Partial:', event.matches?.[0]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await SpeechRecognition.start({
|
|
39
|
+
language: 'en-US',
|
|
40
|
+
maxResults: 3,
|
|
41
|
+
partialResults: true,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Later, when you want to stop listening
|
|
45
|
+
await SpeechRecognition.stop();
|
|
46
|
+
await partialListener.remove();
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### iOS usage descriptions
|
|
50
|
+
|
|
51
|
+
Add the following keys to your app `Info.plist`:
|
|
52
|
+
|
|
53
|
+
- `NSSpeechRecognitionUsageDescription`
|
|
54
|
+
- `NSMicrophoneUsageDescription`
|
|
55
|
+
|
|
56
|
+
## API
|
|
57
|
+
|
|
58
|
+
<docgen-index>
|
|
59
|
+
|
|
60
|
+
* [`available()`](#available)
|
|
61
|
+
* [`start(...)`](#start)
|
|
62
|
+
* [`stop()`](#stop)
|
|
63
|
+
* [`getSupportedLanguages()`](#getsupportedlanguages)
|
|
64
|
+
* [`isListening()`](#islistening)
|
|
65
|
+
* [`checkPermissions()`](#checkpermissions)
|
|
66
|
+
* [`requestPermissions()`](#requestpermissions)
|
|
67
|
+
* [`addListener('endOfSegmentedSession', ...)`](#addlistenerendofsegmentedsession-)
|
|
68
|
+
* [`addListener('segmentResults', ...)`](#addlistenersegmentresults-)
|
|
69
|
+
* [`addListener('partialResults', ...)`](#addlistenerpartialresults-)
|
|
70
|
+
* [`addListener('listeningState', ...)`](#addlistenerlisteningstate-)
|
|
71
|
+
* [`removeAllListeners()`](#removealllisteners)
|
|
72
|
+
* [Interfaces](#interfaces)
|
|
73
|
+
* [Type Aliases](#type-aliases)
|
|
74
|
+
|
|
75
|
+
</docgen-index>
|
|
76
|
+
|
|
77
|
+
<docgen-api>
|
|
78
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
79
|
+
|
|
80
|
+
### available()
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
available() => Promise<SpeechRecognitionAvailability>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Checks whether the native speech recognition service is usable on the current device.
|
|
87
|
+
|
|
88
|
+
**Returns:** <code>Promise<<a href="#speechrecognitionavailability">SpeechRecognitionAvailability</a>></code>
|
|
89
|
+
|
|
90
|
+
--------------------
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### start(...)
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
start(options?: SpeechRecognitionStartOptions | undefined) => Promise<SpeechRecognitionMatches>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Begins capturing audio and transcribing speech.
|
|
100
|
+
|
|
101
|
+
When `partialResults` is `true`, the returned promise resolves immediately and updates are
|
|
102
|
+
streamed through the `partialResults` listener until {@link stop} is called.
|
|
103
|
+
|
|
104
|
+
| Param | Type |
|
|
105
|
+
| ------------- | --------------------------------------------------------------------------------------- |
|
|
106
|
+
| **`options`** | <code><a href="#speechrecognitionstartoptions">SpeechRecognitionStartOptions</a></code> |
|
|
107
|
+
|
|
108
|
+
**Returns:** <code>Promise<<a href="#speechrecognitionmatches">SpeechRecognitionMatches</a>></code>
|
|
109
|
+
|
|
110
|
+
--------------------
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
### stop()
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
stop() => Promise<void>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Stops listening and tears down native resources.
|
|
120
|
+
|
|
121
|
+
--------------------
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
### getSupportedLanguages()
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
getSupportedLanguages() => Promise<SpeechRecognitionLanguages>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Gets the locales supported by the underlying recognizer.
|
|
131
|
+
|
|
132
|
+
Android 13+ devices no longer expose this list; in that case `languages` is empty.
|
|
133
|
+
|
|
134
|
+
**Returns:** <code>Promise<<a href="#speechrecognitionlanguages">SpeechRecognitionLanguages</a>></code>
|
|
135
|
+
|
|
136
|
+
--------------------
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
### isListening()
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
isListening() => Promise<SpeechRecognitionListening>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Returns whether the plugin is actively listening for speech.
|
|
146
|
+
|
|
147
|
+
**Returns:** <code>Promise<<a href="#speechrecognitionlistening">SpeechRecognitionListening</a>></code>
|
|
148
|
+
|
|
149
|
+
--------------------
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
### checkPermissions()
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
checkPermissions() => Promise<SpeechRecognitionPermissionStatus>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Gets the current permission state.
|
|
159
|
+
|
|
160
|
+
**Returns:** <code>Promise<<a href="#speechrecognitionpermissionstatus">SpeechRecognitionPermissionStatus</a>></code>
|
|
161
|
+
|
|
162
|
+
--------------------
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
### requestPermissions()
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
requestPermissions() => Promise<SpeechRecognitionPermissionStatus>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Requests the microphone + speech recognition permissions.
|
|
172
|
+
|
|
173
|
+
**Returns:** <code>Promise<<a href="#speechrecognitionpermissionstatus">SpeechRecognitionPermissionStatus</a>></code>
|
|
174
|
+
|
|
175
|
+
--------------------
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
### addListener('endOfSegmentedSession', ...)
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
addListener(eventName: 'endOfSegmentedSession', listenerFunc: () => void) => Promise<PluginListenerHandle>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Listen for segmented session completion events (Android only).
|
|
185
|
+
|
|
186
|
+
| Param | Type |
|
|
187
|
+
| ------------------ | ------------------------------------ |
|
|
188
|
+
| **`eventName`** | <code>'endOfSegmentedSession'</code> |
|
|
189
|
+
| **`listenerFunc`** | <code>() => void</code> |
|
|
190
|
+
|
|
191
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
192
|
+
|
|
193
|
+
--------------------
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
### addListener('segmentResults', ...)
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
addListener(eventName: 'segmentResults', listenerFunc: (event: SpeechRecognitionSegmentResultEvent) => void) => Promise<PluginListenerHandle>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Listen for segmented recognition results (Android only).
|
|
203
|
+
|
|
204
|
+
| Param | Type |
|
|
205
|
+
| ------------------ | ----------------------------------------------------------------------------------------------------------------------- |
|
|
206
|
+
| **`eventName`** | <code>'segmentResults'</code> |
|
|
207
|
+
| **`listenerFunc`** | <code>(event: <a href="#speechrecognitionsegmentresultevent">SpeechRecognitionSegmentResultEvent</a>) => void</code> |
|
|
208
|
+
|
|
209
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
210
|
+
|
|
211
|
+
--------------------
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
### addListener('partialResults', ...)
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
addListener(eventName: 'partialResults', listenerFunc: (event: SpeechRecognitionPartialResultEvent) => void) => Promise<PluginListenerHandle>
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Listen for partial transcription updates emitted while `partialResults` is enabled.
|
|
221
|
+
|
|
222
|
+
| Param | Type |
|
|
223
|
+
| ------------------ | ----------------------------------------------------------------------------------------------------------------------- |
|
|
224
|
+
| **`eventName`** | <code>'partialResults'</code> |
|
|
225
|
+
| **`listenerFunc`** | <code>(event: <a href="#speechrecognitionpartialresultevent">SpeechRecognitionPartialResultEvent</a>) => void</code> |
|
|
226
|
+
|
|
227
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
228
|
+
|
|
229
|
+
--------------------
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
### addListener('listeningState', ...)
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
addListener(eventName: 'listeningState', listenerFunc: (event: SpeechRecognitionListeningEvent) => void) => Promise<PluginListenerHandle>
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Listen for changes to the native listening state.
|
|
239
|
+
|
|
240
|
+
| Param | Type |
|
|
241
|
+
| ------------------ | --------------------------------------------------------------------------------------------------------------- |
|
|
242
|
+
| **`eventName`** | <code>'listeningState'</code> |
|
|
243
|
+
| **`listenerFunc`** | <code>(event: <a href="#speechrecognitionlisteningevent">SpeechRecognitionListeningEvent</a>) => void</code> |
|
|
244
|
+
|
|
245
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
246
|
+
|
|
247
|
+
--------------------
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
### removeAllListeners()
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
removeAllListeners() => Promise<void>
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Removes every registered listener.
|
|
257
|
+
|
|
258
|
+
--------------------
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
### Interfaces
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
#### SpeechRecognitionAvailability
|
|
265
|
+
|
|
266
|
+
| Prop | Type |
|
|
267
|
+
| --------------- | -------------------- |
|
|
268
|
+
| **`available`** | <code>boolean</code> |
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
#### SpeechRecognitionMatches
|
|
272
|
+
|
|
273
|
+
| Prop | Type |
|
|
274
|
+
| ------------- | --------------------- |
|
|
275
|
+
| **`matches`** | <code>string[]</code> |
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
#### SpeechRecognitionStartOptions
|
|
279
|
+
|
|
280
|
+
Configure how the recognizer behaves when calling {@link SpeechRecognitionPlugin.start}.
|
|
281
|
+
|
|
282
|
+
| Prop | Type | Description |
|
|
283
|
+
| --------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
284
|
+
| **`language`** | <code>string</code> | Locale identifier such as `en-US`. When omitted the device language is used. |
|
|
285
|
+
| **`maxResults`** | <code>number</code> | Maximum number of final matches returned by native APIs. Defaults to `5`. |
|
|
286
|
+
| **`prompt`** | <code>string</code> | Prompt message shown inside the Android system dialog (ignored on iOS). |
|
|
287
|
+
| **`popup`** | <code>boolean</code> | When `true`, Android shows the OS speech dialog instead of running inline recognition. Defaults to `false`. |
|
|
288
|
+
| **`partialResults`** | <code>boolean</code> | Emits partial transcription updates through the `partialResults` listener while audio is captured. |
|
|
289
|
+
| **`addPunctuation`** | <code>boolean</code> | Enables native punctuation handling where supported (iOS 16+). |
|
|
290
|
+
| **`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. |
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
#### SpeechRecognitionLanguages
|
|
294
|
+
|
|
295
|
+
| Prop | Type |
|
|
296
|
+
| --------------- | --------------------- |
|
|
297
|
+
| **`languages`** | <code>string[]</code> |
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
#### SpeechRecognitionListening
|
|
301
|
+
|
|
302
|
+
| Prop | Type |
|
|
303
|
+
| --------------- | -------------------- |
|
|
304
|
+
| **`listening`** | <code>boolean</code> |
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
#### SpeechRecognitionPermissionStatus
|
|
308
|
+
|
|
309
|
+
Permission map returned by `checkPermissions` and `requestPermissions`.
|
|
310
|
+
|
|
311
|
+
On Android the state maps to the `RECORD_AUDIO` permission.
|
|
312
|
+
On iOS it combines speech recognition plus microphone permission.
|
|
313
|
+
|
|
314
|
+
| Prop | Type |
|
|
315
|
+
| ----------------------- | ----------------------------------------------------------- |
|
|
316
|
+
| **`speechRecognition`** | <code><a href="#permissionstate">PermissionState</a></code> |
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
#### PluginListenerHandle
|
|
320
|
+
|
|
321
|
+
| Prop | Type |
|
|
322
|
+
| ------------ | ----------------------------------------- |
|
|
323
|
+
| **`remove`** | <code>() => Promise<void></code> |
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
#### SpeechRecognitionSegmentResultEvent
|
|
327
|
+
|
|
328
|
+
Raised whenever a segmented result is produced (Android only).
|
|
329
|
+
|
|
330
|
+
| Prop | Type |
|
|
331
|
+
| ------------- | --------------------- |
|
|
332
|
+
| **`matches`** | <code>string[]</code> |
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
#### SpeechRecognitionPartialResultEvent
|
|
336
|
+
|
|
337
|
+
Raised whenever a partial transcription is produced.
|
|
338
|
+
|
|
339
|
+
| Prop | Type |
|
|
340
|
+
| ------------- | --------------------- |
|
|
341
|
+
| **`matches`** | <code>string[]</code> |
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
#### SpeechRecognitionListeningEvent
|
|
345
|
+
|
|
346
|
+
Raised when the listening state changes.
|
|
347
|
+
|
|
348
|
+
| Prop | Type |
|
|
349
|
+
| ------------ | ----------------------------------- |
|
|
350
|
+
| **`status`** | <code>'started' \| 'stopped'</code> |
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
### Type Aliases
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
#### PermissionState
|
|
357
|
+
|
|
358
|
+
<code>'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'</code>
|
|
359
|
+
|
|
360
|
+
</docgen-api>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.7.2'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace "app.capgo.speechrecognition"
|
|
22
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
dependencies {
|
|
51
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
52
|
+
implementation project(':capacitor-android')
|
|
53
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
54
|
+
testImplementation "junit:junit:$junitVersion"
|
|
55
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
57
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package app.capgo.speechrecognition;
|
|
2
|
+
|
|
3
|
+
import android.Manifest;
|
|
4
|
+
|
|
5
|
+
public interface Constants {
|
|
6
|
+
int REQUEST_CODE_PERMISSION = 2001;
|
|
7
|
+
int REQUEST_CODE_SPEECH = 2002;
|
|
8
|
+
int MAX_RESULTS = 5;
|
|
9
|
+
String NOT_AVAILABLE = "Speech recognition service is not available.";
|
|
10
|
+
String MISSING_PERMISSION = "Missing permission";
|
|
11
|
+
String SEGMENT_RESULTS_EVENT = "segmentResults";
|
|
12
|
+
String END_OF_SEGMENT_EVENT = "endOfSegmentedSession";
|
|
13
|
+
String LISTENING_EVENT = "listeningState";
|
|
14
|
+
String PARTIAL_RESULTS_EVENT = "partialResults";
|
|
15
|
+
String RECORD_AUDIO_PERMISSION = Manifest.permission.RECORD_AUDIO;
|
|
16
|
+
String LANGUAGE_ERROR = "Could not get list of languages";
|
|
17
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
package app.capgo.speechrecognition;
|
|
2
|
+
|
|
3
|
+
import android.content.BroadcastReceiver;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.os.Bundle;
|
|
7
|
+
import android.speech.RecognizerIntent;
|
|
8
|
+
import com.getcapacitor.JSArray;
|
|
9
|
+
import com.getcapacitor.JSObject;
|
|
10
|
+
import com.getcapacitor.PluginCall;
|
|
11
|
+
import java.util.List;
|
|
12
|
+
|
|
13
|
+
public class Receiver extends BroadcastReceiver implements Constants {
|
|
14
|
+
private List<String> supportedLanguagesList;
|
|
15
|
+
private String languagePref;
|
|
16
|
+
private final PluginCall call;
|
|
17
|
+
|
|
18
|
+
public Receiver(PluginCall call) {
|
|
19
|
+
super();
|
|
20
|
+
this.call = call;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Override
|
|
24
|
+
public void onReceive(Context context, Intent intent) {
|
|
25
|
+
Bundle extras = getResultExtras(true);
|
|
26
|
+
|
|
27
|
+
if (extras.containsKey(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE)) {
|
|
28
|
+
languagePref = extras.getString(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (extras.containsKey(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES)) {
|
|
32
|
+
supportedLanguagesList = extras.getStringArrayList(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES);
|
|
33
|
+
|
|
34
|
+
JSArray languagesList = new JSArray(supportedLanguagesList);
|
|
35
|
+
call.resolve(new JSObject().put("languages", languagesList));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
call.reject(LANGUAGE_ERROR);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public List<String> getSupportedLanguages() {
|
|
43
|
+
return supportedLanguagesList;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public String getLanguagePreference() {
|
|
47
|
+
return languagePref;
|
|
48
|
+
}
|
|
49
|
+
}
|