expo-speech-recognition 58.1.1 → 58.2.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/README.md +5 -0
- package/android/src/main/java/expo/modules/speechrecognition/DelayedFileStreamer.kt +0 -1
- package/android/src/main/java/expo/modules/speechrecognition/ExpoSpeechRecognitionModule.kt +0 -2
- package/android/src/main/java/expo/modules/speechrecognition/ExpoSpeechRecognitionOptions.kt +7 -0
- package/android/src/main/java/expo/modules/speechrecognition/ExpoSpeechService.kt +134 -14
- package/build/ExpoSpeechRecognitionModule.types.d.ts +20 -0
- package/build/ExpoSpeechRecognitionModule.types.d.ts.map +1 -1
- package/build/ExpoSpeechRecognitionModule.types.js.map +1 -1
- package/ios/ExpoSpeechRecognitionModule.swift +51 -12
- package/ios/ExpoSpeechRecognizer.swift +78 -42
- package/package.json +1 -1
- package/src/ExpoSpeechRecognitionModule.types.ts +20 -0
package/README.md
CHANGED
|
@@ -278,6 +278,11 @@ ExpoSpeechRecognitionModule.start({
|
|
|
278
278
|
},
|
|
279
279
|
// [Default: undefined] The package name of the speech recognition service to use.
|
|
280
280
|
androidRecognitionServicePackage: "com.google.android.tts",
|
|
281
|
+
// [Default: false] [Android only] Pause other apps' playback (music, podcasts)
|
|
282
|
+
// while recognizing from the microphone, and let it resume afterwards.
|
|
283
|
+
// Mainly useful with `continuous` or `recordingOptions.persist`: without those,
|
|
284
|
+
// some recognition services (e.g. Google's) already request audio focus themselves.
|
|
285
|
+
androidAudioFocus: true,
|
|
281
286
|
// [Default: unspecified] The type of speech recognition being performed.
|
|
282
287
|
iosTaskHint: "unspecified", // "unspecified" | "dictation" | "search" | "confirmation"
|
|
283
288
|
// [Default: undefined] The audio session category and options to use.
|
|
@@ -217,7 +217,6 @@ class ExpoSpeechRecognitionModule : Module() {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
Function("abort") {
|
|
220
|
-
sendEvent("error", mapOf("error" to "aborted", "message" to "Speech recognition aborted.", "code" to -1))
|
|
221
220
|
expoSpeechService.abort()
|
|
222
221
|
}
|
|
223
222
|
|
|
@@ -440,7 +439,6 @@ class ExpoSpeechRecognitionModule : Module() {
|
|
|
440
439
|
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
|
441
440
|
object : RecognitionSupportCallback {
|
|
442
441
|
override fun onSupportResult(recognitionSupport: RecognitionSupport) {
|
|
443
|
-
Log.d("ExpoSpeechService", "onSupportResult() called with recognitionSupport: $recognitionSupport")
|
|
444
442
|
if (!settled.compareAndSet(false, true)) {
|
|
445
443
|
return
|
|
446
444
|
}
|
package/android/src/main/java/expo/modules/speechrecognition/ExpoSpeechRecognitionOptions.kt
CHANGED
|
@@ -47,6 +47,13 @@ class SpeechRecognitionOptions : Record {
|
|
|
47
47
|
@Field
|
|
48
48
|
val androidIntent: String? = RecognizerIntent.ACTION_RECOGNIZE_SPEECH
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Request transient exclusive audio focus while recognizing from the microphone,
|
|
52
|
+
* so that other apps pause their playback until recognition ends.
|
|
53
|
+
*/
|
|
54
|
+
@Field
|
|
55
|
+
val androidAudioFocus: Boolean? = false
|
|
56
|
+
|
|
50
57
|
@Field
|
|
51
58
|
val iosTaskHint: String? = null
|
|
52
59
|
|
|
@@ -5,7 +5,10 @@ import android.content.ComponentName
|
|
|
5
5
|
import android.content.Context
|
|
6
6
|
import android.content.Intent
|
|
7
7
|
import android.content.pm.ResolveInfo
|
|
8
|
+
import android.media.AudioAttributes
|
|
9
|
+
import android.media.AudioFocusRequest
|
|
8
10
|
import android.media.AudioFormat
|
|
11
|
+
import android.media.AudioManager
|
|
9
12
|
import android.os.Build
|
|
10
13
|
import android.os.Bundle
|
|
11
14
|
import android.os.Handler
|
|
@@ -19,6 +22,7 @@ import android.util.Log
|
|
|
19
22
|
import java.io.File
|
|
20
23
|
import java.net.URI
|
|
21
24
|
import java.util.Locale
|
|
25
|
+
import java.util.concurrent.atomic.AtomicInteger
|
|
22
26
|
|
|
23
27
|
data class SpeechRecognitionErrorEvent(
|
|
24
28
|
val error: String,
|
|
@@ -51,6 +55,12 @@ class ExpoSpeechService(
|
|
|
51
55
|
private val mainHandler = Handler(Looper.getMainLooper())
|
|
52
56
|
|
|
53
57
|
private lateinit var options: SpeechRecognitionOptions
|
|
58
|
+
|
|
59
|
+
/** Bumped by start() and abort(), so that abort() cancels a start() that hasn't run yet */
|
|
60
|
+
private val startGeneration = AtomicInteger()
|
|
61
|
+
|
|
62
|
+
/** Whether "audiostart" was emitted without a matching "audioend" yet */
|
|
63
|
+
private var hasEmittedAudioStart = false
|
|
54
64
|
private var lastVolumeChangeEventTime: Long = 0L
|
|
55
65
|
|
|
56
66
|
/** Audio recorder for persisting audio */
|
|
@@ -63,6 +73,11 @@ class ExpoSpeechService(
|
|
|
63
73
|
private var lastDetectedLanguage: String? = null
|
|
64
74
|
private var lastLanguageConfidence: Float? = null
|
|
65
75
|
|
|
76
|
+
/** Audio focus held during recognition when `androidAudioFocus` is enabled */
|
|
77
|
+
private var hasAudioFocus = false
|
|
78
|
+
private var audioFocusRequest: AudioFocusRequest? = null
|
|
79
|
+
private var audioFocusChangeListener: AudioManager.OnAudioFocusChangeListener? = null
|
|
80
|
+
|
|
66
81
|
var recognitionState = RecognitionState.INACTIVE
|
|
67
82
|
|
|
68
83
|
companion object {
|
|
@@ -115,7 +130,12 @@ class ExpoSpeechService(
|
|
|
115
130
|
/** Starts speech recognition */
|
|
116
131
|
fun start(options: SpeechRecognitionOptions) {
|
|
117
132
|
this.options = options
|
|
133
|
+
val generation = startGeneration.incrementAndGet()
|
|
118
134
|
mainHandler.post {
|
|
135
|
+
if (generation != startGeneration.get()) {
|
|
136
|
+
// abort() or a newer start() was called before this one ran
|
|
137
|
+
return@post
|
|
138
|
+
}
|
|
119
139
|
log("Start recognition.")
|
|
120
140
|
|
|
121
141
|
// Destroy any previous SpeechRecognizer / audio recorder
|
|
@@ -135,6 +155,13 @@ class ExpoSpeechService(
|
|
|
135
155
|
soundState = SoundState.INACTIVE
|
|
136
156
|
lastVolumeChangeEventTime = 0L
|
|
137
157
|
try {
|
|
158
|
+
// Pause other apps' playback (music, podcasts) while listening to the microphone
|
|
159
|
+
if (options.androidAudioFocus == true && options.audioSource == null) {
|
|
160
|
+
requestAudioFocus()
|
|
161
|
+
} else {
|
|
162
|
+
abandonAudioFocus()
|
|
163
|
+
}
|
|
164
|
+
|
|
138
165
|
val intent = createSpeechIntent(options)
|
|
139
166
|
speech = createSpeechRecognizer(options)
|
|
140
167
|
|
|
@@ -151,6 +178,7 @@ class ExpoSpeechService(
|
|
|
151
178
|
|
|
152
179
|
delayedFileStreamer?.startStreaming()
|
|
153
180
|
|
|
181
|
+
hasEmittedAudioStart = true
|
|
154
182
|
sendEvent(
|
|
155
183
|
"audiostart",
|
|
156
184
|
mapOf(
|
|
@@ -178,6 +206,11 @@ class ExpoSpeechService(
|
|
|
178
206
|
*/
|
|
179
207
|
private fun stopRecording() {
|
|
180
208
|
audioRecorder?.stop()
|
|
209
|
+
if (!hasEmittedAudioStart) {
|
|
210
|
+
audioRecorder = null
|
|
211
|
+
return
|
|
212
|
+
}
|
|
213
|
+
hasEmittedAudioStart = false
|
|
181
214
|
val timestamp = audioRecorder?.stoppedAtMillis ?: System.currentTimeMillis()
|
|
182
215
|
if (audioRecorder?.outputFile != null) {
|
|
183
216
|
val uri = audioRecorder?.outputFile?.absolutePath?.let { "file://$it" }
|
|
@@ -206,6 +239,11 @@ class ExpoSpeechService(
|
|
|
206
239
|
*/
|
|
207
240
|
fun stop() {
|
|
208
241
|
mainHandler.post {
|
|
242
|
+
if (speech == null) {
|
|
243
|
+
// Nothing is running, e.g. recognition ended just before this call
|
|
244
|
+
teardownAndEnd()
|
|
245
|
+
return@post
|
|
246
|
+
}
|
|
209
247
|
recognitionState = RecognitionState.STOPPING
|
|
210
248
|
try {
|
|
211
249
|
speech?.stopListening()
|
|
@@ -223,6 +261,11 @@ class ExpoSpeechService(
|
|
|
223
261
|
* final result is emitted.
|
|
224
262
|
*/
|
|
225
263
|
fun abort() {
|
|
264
|
+
startGeneration.incrementAndGet()
|
|
265
|
+
// Posted, so that it can't overtake the events of a start() that is running on the main thread
|
|
266
|
+
mainHandler.post {
|
|
267
|
+
sendEvent("error", mapOf("error" to "aborted", "message" to "Speech recognition aborted.", "code" to -1))
|
|
268
|
+
}
|
|
226
269
|
teardownAndEnd()
|
|
227
270
|
}
|
|
228
271
|
|
|
@@ -237,10 +280,22 @@ class ExpoSpeechService(
|
|
|
237
280
|
|
|
238
281
|
/**
|
|
239
282
|
* Stops speech recognition, recording and updates state
|
|
283
|
+
*
|
|
284
|
+
* @param onlyIfActive Skip the teardown when the session has already been torn down.
|
|
285
|
+
* Recognizer callbacks can overlap (e.g. onError + onEndOfSegmentedSession) and should emit a single "end" event.
|
|
240
286
|
*/
|
|
241
|
-
private fun teardownAndEnd(
|
|
287
|
+
private fun teardownAndEnd(
|
|
288
|
+
state: RecognitionState = RecognitionState.INACTIVE,
|
|
289
|
+
onlyIfActive: Boolean = false,
|
|
290
|
+
) {
|
|
291
|
+
if (onlyIfActive && speech == null) {
|
|
292
|
+
return
|
|
293
|
+
}
|
|
242
294
|
recognitionState = RecognitionState.STOPPING
|
|
243
295
|
mainHandler.post {
|
|
296
|
+
if (onlyIfActive && speech == null) {
|
|
297
|
+
return@post
|
|
298
|
+
}
|
|
244
299
|
try {
|
|
245
300
|
speech?.cancel()
|
|
246
301
|
} catch (e: Exception) {
|
|
@@ -253,6 +308,7 @@ class ExpoSpeechService(
|
|
|
253
308
|
}
|
|
254
309
|
speech = null
|
|
255
310
|
stopRecording()
|
|
311
|
+
abandonAudioFocus()
|
|
256
312
|
soundState = SoundState.INACTIVE
|
|
257
313
|
sendEvent("end", null)
|
|
258
314
|
recognitionState = state
|
|
@@ -261,6 +317,79 @@ class ExpoSpeechService(
|
|
|
261
317
|
}
|
|
262
318
|
}
|
|
263
319
|
|
|
320
|
+
/**
|
|
321
|
+
* Requests transient exclusive audio focus, the focus type Android recommends for speech recognition.
|
|
322
|
+
* Other apps pause their playback and resume it when the focus is abandoned.
|
|
323
|
+
*/
|
|
324
|
+
private fun requestAudioFocus() {
|
|
325
|
+
if (hasAudioFocus) {
|
|
326
|
+
return
|
|
327
|
+
}
|
|
328
|
+
val audioManager = reactContext.getSystemService(Context.AUDIO_SERVICE) as? AudioManager ?: return
|
|
329
|
+
// One listener per request, so that a late callback for an earlier request can be told apart
|
|
330
|
+
val listener =
|
|
331
|
+
object : AudioManager.OnAudioFocusChangeListener {
|
|
332
|
+
override fun onAudioFocusChange(focusChange: Int) {
|
|
333
|
+
if (focusChange == AudioManager.AUDIOFOCUS_LOSS && audioFocusChangeListener === this) {
|
|
334
|
+
// Another app took the focus for good, so the next start() has to request it again
|
|
335
|
+
abandonAudioFocus()
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
audioFocusChangeListener = listener
|
|
340
|
+
val result =
|
|
341
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
342
|
+
val request =
|
|
343
|
+
AudioFocusRequest
|
|
344
|
+
.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE)
|
|
345
|
+
.setAudioAttributes(
|
|
346
|
+
AudioAttributes
|
|
347
|
+
.Builder()
|
|
348
|
+
.setUsage(AudioAttributes.USAGE_ASSISTANT)
|
|
349
|
+
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
|
|
350
|
+
.build(),
|
|
351
|
+
).setOnAudioFocusChangeListener(listener, mainHandler)
|
|
352
|
+
.build()
|
|
353
|
+
audioFocusRequest = request
|
|
354
|
+
audioManager.requestAudioFocus(request)
|
|
355
|
+
} else {
|
|
356
|
+
@Suppress("DEPRECATION")
|
|
357
|
+
audioManager.requestAudioFocus(
|
|
358
|
+
listener,
|
|
359
|
+
AudioManager.STREAM_MUSIC,
|
|
360
|
+
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE,
|
|
361
|
+
)
|
|
362
|
+
}
|
|
363
|
+
hasAudioFocus = result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED
|
|
364
|
+
if (!hasAudioFocus) {
|
|
365
|
+
clearAudioFocusState()
|
|
366
|
+
}
|
|
367
|
+
log("Audio focus request granted: $hasAudioFocus")
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** Abandons the audio focus, so that other apps can resume their playback */
|
|
371
|
+
private fun abandonAudioFocus() {
|
|
372
|
+
if (!hasAudioFocus) {
|
|
373
|
+
return
|
|
374
|
+
}
|
|
375
|
+
val audioManager = reactContext.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
|
|
376
|
+
if (audioManager != null) {
|
|
377
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
378
|
+
audioFocusRequest?.let { audioManager.abandonAudioFocusRequest(it) }
|
|
379
|
+
} else {
|
|
380
|
+
@Suppress("DEPRECATION")
|
|
381
|
+
audioFocusChangeListener?.let { audioManager.abandonAudioFocus(it) }
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
clearAudioFocusState()
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
private fun clearAudioFocusState() {
|
|
388
|
+
hasAudioFocus = false
|
|
389
|
+
audioFocusRequest = null
|
|
390
|
+
audioFocusChangeListener = null
|
|
391
|
+
}
|
|
392
|
+
|
|
264
393
|
private fun createSpeechIntent(options: SpeechRecognitionOptions): Intent {
|
|
265
394
|
val action = options.androidIntent ?: RecognizerIntent.ACTION_RECOGNIZE_SPEECH
|
|
266
395
|
val intent = Intent(action)
|
|
@@ -334,7 +463,6 @@ class ExpoSpeechService(
|
|
|
334
463
|
throw Exception("Audio source is only supported on Android 13 and above")
|
|
335
464
|
}
|
|
336
465
|
|
|
337
|
-
log("Transcribing audio from local file: ${options.audioSource.uri}")
|
|
338
466
|
val file = resolveSourceUri(options.audioSource.uri)
|
|
339
467
|
|
|
340
468
|
// The file should exist, otherwise throw an error
|
|
@@ -381,8 +509,6 @@ class ExpoSpeechService(
|
|
|
381
509
|
if (!contextualStrings.isNullOrEmpty() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
382
510
|
// Optional list of strings, towards which the recognizer should bias the recognition results.
|
|
383
511
|
// These are separate from the device context.
|
|
384
|
-
val strings = ArrayList(contextualStrings)
|
|
385
|
-
log("biasing strings: ${strings.joinToString(", ")}")
|
|
386
512
|
intent.putExtra(
|
|
387
513
|
RecognizerIntent.EXTRA_BIASING_STRINGS,
|
|
388
514
|
// List<String> -> ArrayList<java.lang.String>
|
|
@@ -407,8 +533,6 @@ class ExpoSpeechService(
|
|
|
407
533
|
val language = options.lang.takeIf { it.isNotEmpty() } ?: Locale.getDefault().toString()
|
|
408
534
|
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language)
|
|
409
535
|
|
|
410
|
-
log("androidIntentOptions: ${options.androidIntentOptions}")
|
|
411
|
-
|
|
412
536
|
// Add any additional intent extras provided by the user
|
|
413
537
|
options.androidIntentOptions?.forEach { (key, value) ->
|
|
414
538
|
// Use reflection to set the extra
|
|
@@ -416,7 +540,6 @@ class ExpoSpeechService(
|
|
|
416
540
|
val field = RecognizerIntent::class.java.getDeclaredField(key)
|
|
417
541
|
val fieldValue = field.get(null) as? String
|
|
418
542
|
|
|
419
|
-
log("Resolved key $key -> $fieldValue with value: $value (${value.javaClass.name})")
|
|
420
543
|
when (value) {
|
|
421
544
|
is Boolean -> intent.putExtra(fieldValue, value)
|
|
422
545
|
is Int -> intent.putExtra(fieldValue, value)
|
|
@@ -543,7 +666,7 @@ class ExpoSpeechService(
|
|
|
543
666
|
}
|
|
544
667
|
|
|
545
668
|
sendEvent("error", mapOf("error" to errorInfo.error, "message" to errorInfo.message, "code" to error))
|
|
546
|
-
teardownAndEnd(RecognitionState.ERROR)
|
|
669
|
+
teardownAndEnd(RecognitionState.ERROR, onlyIfActive = true)
|
|
547
670
|
log("onError() - ${errorInfo.error}: ${errorInfo.message} - code: $error")
|
|
548
671
|
}
|
|
549
672
|
|
|
@@ -633,9 +756,8 @@ class ExpoSpeechService(
|
|
|
633
756
|
),
|
|
634
757
|
)
|
|
635
758
|
}
|
|
636
|
-
log("onResults(), results: $resultsList")
|
|
637
759
|
|
|
638
|
-
teardownAndEnd()
|
|
760
|
+
teardownAndEnd(onlyIfActive = true)
|
|
639
761
|
}
|
|
640
762
|
|
|
641
763
|
override fun onPartialResults(partialResults: Bundle?) {
|
|
@@ -643,7 +765,6 @@ class ExpoSpeechService(
|
|
|
643
765
|
// Avoid sending result event if there was an empty result, or the first result is an empty string
|
|
644
766
|
val nonEmptyStrings = partialResultsList.filter { it["transcript"]?.toString()?.isNotEmpty() ?: false }
|
|
645
767
|
|
|
646
|
-
log("onPartialResults(), results: $nonEmptyStrings")
|
|
647
768
|
if (nonEmptyStrings.isNotEmpty()) {
|
|
648
769
|
sendEvent("result", mapOf("results" to nonEmptyStrings, "isFinal" to false))
|
|
649
770
|
}
|
|
@@ -685,17 +806,16 @@ class ExpoSpeechService(
|
|
|
685
806
|
),
|
|
686
807
|
)
|
|
687
808
|
}
|
|
688
|
-
log("onSegmentResults(), transcriptions: $resultsList")
|
|
689
809
|
|
|
690
810
|
// If the user opted to stop
|
|
691
811
|
if (recognitionState == RecognitionState.STOPPING) {
|
|
692
|
-
teardownAndEnd()
|
|
812
|
+
teardownAndEnd(onlyIfActive = true)
|
|
693
813
|
}
|
|
694
814
|
}
|
|
695
815
|
|
|
696
816
|
override fun onEndOfSegmentedSession() {
|
|
697
817
|
log("onEndOfSegmentedSession()")
|
|
698
|
-
teardownAndEnd()
|
|
818
|
+
teardownAndEnd(onlyIfActive = true)
|
|
699
819
|
}
|
|
700
820
|
|
|
701
821
|
override fun onEvent(
|
|
@@ -226,6 +226,26 @@ export type ExpoSpeechRecognitionOptions = {
|
|
|
226
226
|
* e.g. "com.google.android.as" or "com.samsung.android.bixby.agent"
|
|
227
227
|
*/
|
|
228
228
|
androidRecognitionServicePackage?: string;
|
|
229
|
+
/**
|
|
230
|
+
* [Android only] Request audio focus while recognizing from the microphone.
|
|
231
|
+
*
|
|
232
|
+
* Other apps (e.g. music or podcast players) pause their playback when recognition starts,
|
|
233
|
+
* and resume it when recognition ends.
|
|
234
|
+
*
|
|
235
|
+
* This requests [`AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE`](https://developer.android.com/reference/android/media/AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE),
|
|
236
|
+
* the focus type Android recommends for speech recognition. It has no effect when `audioSource` is set.
|
|
237
|
+
*
|
|
238
|
+
* This is mainly useful with `continuous` or `recordingOptions.persist`. Without those,
|
|
239
|
+
* some recognition services (e.g. Google's) already request audio focus themselves.
|
|
240
|
+
*
|
|
241
|
+
* The focus is held for the duration of a session, so if you call `start()` again from the "end" event,
|
|
242
|
+
* other apps may briefly resume their playback between sessions.
|
|
243
|
+
*
|
|
244
|
+
* On iOS, use `iosCategory` to control how other apps' audio is handled.
|
|
245
|
+
*
|
|
246
|
+
* Default: false
|
|
247
|
+
*/
|
|
248
|
+
androidAudioFocus?: boolean;
|
|
229
249
|
/**
|
|
230
250
|
* Extra options to provide to the Android Recognition intent.
|
|
231
251
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoSpeechRecognitionModule.types.d.ts","sourceRoot":"","sources":["../src/ExpoSpeechRecognitionModule.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,MAAM,MAAM,uCAAuC,GAAG,kBAAkB,GAAG;IACzE;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,6BAA6B,EAC7B,kBAAkB,EAClB,oC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;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,2BAA2B,CAAC;IACtC,eAAe,EAAE,kCAAkC,EAAE,CAAC;IACtD,IAAI,CAAC,EAAE,uBAAuB,CAAC;CAChC,CAAC;AAEF,KAAK,sBAAsB,GACvB,UAAU,GACV,UAAU,GACV,aAAa,GACb,UAAU,CAAC;AAEf;;;;GAIG;AACH,MAAM,MAAM,kCAAkC,GAC5C,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,OAAO,6BAA6B,CAAC,CAAC;AAErF;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GACjC,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"ExpoSpeechRecognitionModule.types.d.ts","sourceRoot":"","sources":["../src/ExpoSpeechRecognitionModule.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,MAAM,MAAM,uCAAuC,GAAG,kBAAkB,GAAG;IACzE;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,6BAA6B,EAC7B,kBAAkB,EAClB,oCAAoC,EACpC,kCAAkC,EAClC,WAAW,EACZ,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,2BAA2B,GACrC,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,OAAO,sBAAsB,CAAC,CAAC;AAEvE,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,EAAE,kCAAkC,EAAE,CAAC;CAChD,CAAC;AAEF,MAAM,MAA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AAO,6BAA6B,CAAC,CAAC,MAAM,OAAO,6BAA6B,CAAC,CAAC;AAErF;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GACjC,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoSpeechRecognitionModule.types.js","sourceRoot":"","sources":["../src/ExpoSpeechRecognitionModule.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionResponse } from \"expo-modules-core\";\nimport type { NativeModule } from \"expo\";\n\nexport type ExpoSpeechRecognitionPermissionResponse = PermissionResponse & {\n /**\n * Whether the speech recognition is restricted by Content & Privacy Restrictions.\n *\n * This value corresponds to the `restricted` enum of `SFSpeechRecognizer.authorizationStatus()`.\n *\n * This is only available on iOS.\n */\n restricted?: boolean;\n};\n\nimport type {\n AudioEncodingAndroid,\n AVAudioSessionCategory,\n AVAudioSessionCategoryOptions,\n AVAudioSessionMode,\n RecognizerIntentEnableLanguageSwitch,\n RecognizerIntentExtraLanguageModel,\n TaskHintIOS,\n} from \"./constants\";\n\nexport type AVAudioSessionCategoryValue =\n (typeof AVAudioSessionCategory)[keyof typeof AVAudioSessionCategory];\n\nexport type ExpoSpeechRecognitionResult = {\n transcript: string;\n /**\n * Value ranging between between 0.0, 1.0, and -1 (unavailable) indicating transcript confidence.\n */\n confidence: number;\n /**\n * An array of transcription segments that represent the parts of the transcription, as identified by the speech recognizer.\n *\n * Notes for Android:\n *\n * - This is only available for SDK 34+ (Android 14+)\n * - This is only verified to work with the `com.google.android.as` service (using on device speech recognition)\n * - Segments are only available during the final result\n * - The segment parts are split up by words.\n * - The segments are only available for the first transcript\n * - Segment confidences currently return as -1 (unavailable)\n *\n * Notes for iOS:\n *\n * - The confidence value will be 0 on partial results\n */\n segments: ExpoSpeechRecognitionResultSegment[];\n};\n\nexport type ExpoSpeechRecognitionResultSegment = {\n /** The start timestamp of the utterance, e.g. 1000 */\n startTimeMillis: number;\n /** The end timestamp of the utterance, e.g. 1500 */\n endTimeMillis: number;\n /** The text portion of the transcript, e.g. \"Hello world\" */\n segment: string;\n /** Value ranging between between 0.0, 1.0, and -1 (unavailable) indicating the confidence of the specific segment */\n confidence: number;\n};\n\n/** Fired when there's a speech result. The result may be partial or final */\nexport type ExpoSpeechRecognitionResultEvent = {\n isFinal: boolean;\n results: ExpoSpeechRecognitionResult[];\n};\n\nexport type ExpoSpeechRecognitionErrorCode =\n /** The user called `ExpoSpeechRecognitionModule.abort()`. */\n | \"aborted\"\n /** Audio recording error. */\n | \"audio-capture\"\n /** (iOS) The audio session was interrupted (phone call, Siri, alarm). */\n | \"interrupted\"\n /** There was an error in the speech recognition grammar or semantic tags, or the chosen grammar format or semantic tag format was unsupported. */\n | \"bad-grammar\"\n /** Locale is not supported by the speech recognizer. */\n | \"language-not-supported\"\n /** Network communication required for completing the recognition failed. */\n | \"network\"\n /** No final speech was detected. */\n | \"no-speech\"\n /** Permission to use speech recognition or microphone was not granted. */\n | \"not-allowed\"\n /** Recognizer is unavailable. */\n | \"service-not-allowed\"\n // Extra codes (not part of the spec)\n /** The recognizer is busy and cannot accept any new recognition requests. */\n | \"busy\"\n /** (Android only) An unknown client-side error occurred. */\n | \"client\"\n /** (Android) No speech input. */\n | \"speech-timeout\"\n /** (Android 12+) Too many requests from the same client. */\n | \"too-many-requests\"\n /** (Android) Unknown error */\n | \"unknown\";\n\nexport type ExpoSpeechRecognitionErrorEvent = {\n error: ExpoSpeechRecognitionErrorCode;\n message: string;\n /**\n * The underlying native error code from the platform-specific speech recognition service.\n *\n * - On Android: Maps to SpeechRecognizer error constants (e.g., ERROR_AUDIO = 3)\n * - Value of -1 indicates a generic/unknown error or when native code is not available\n *\n * Usually you won't need this field, but it can be useful for debugging purposes.\n */\n code?: number;\n};\n\nexport type LanguageDetectionEvent = {\n /** The language that was detected, in BCP-47 format. e.g. \"en-US\", \"de-DE\" */\n detectedLanguage: string;\n /** The confidence of the detected language. A value ranging between 0.0 and 1.0.\n *\n * Values range from:\n *\n * - 1.0 (highly confident)\n * - 0.8 (confident)\n * - 0.5 (not confident)\n * - 0.0 (unknown)\n */\n confidence: number;\n /** The alternative locales for the same language, in BCP-47 format. e.g. [\"en-US\", \"en-GB\"] */\n topLocaleAlternatives: string[];\n};\n\n/**\n * Events that are dispatched from the native side\n */\nexport type ExpoSpeechRecognitionNativeEventMap = {\n result: ExpoSpeechRecognitionResultEvent;\n error: ExpoSpeechRecognitionErrorEvent;\n start: null;\n speechstart: null;\n speechend: null;\n /** A final result is returned with no significant recognition */\n nomatch: null;\n /** Audio capturing had started */\n audiostart: {\n /**\n * The uri is set when `recordingOptions.persist` is enabled.\n * Do not attempt to use this file until the `audioend` event is emitted.\n *\n * Example URIs:\n *\n * - Android: `file:///data/user/0/expo.modules.speechrecognition.example/cache/recording_1720678500903.wav`\n * - iOS: `file:///path/to/Library/Caches/audio_CD5E6C6C-3D9D-4754-9188-D6FAF97D9DF2.wav`\n */\n uri: string | null;\n /**\n * Epoch milliseconds when audio capturing started, comparable to `Date.now()`.\n * May have a fractional part.\n *\n * With `recordingOptions.persist`, it marks the start of the file to within tens of milliseconds.\n *\n * iOS: an audio route change mid-recording, such as connecting headphones, leaves a gap in the file.\n * Positions after the gap drift from this timestamp.\n */\n timestamp: number;\n };\n /** Audio capturing had ended */\n audioend: {\n /**\n * The uri is set when `recordingOptions.persist` is enabled.\n *\n * Example URIs:\n *\n * - Android: `file:///data/user/0/expo.modules.speechrecognition.example/cache/recording_1720678500903.wav`\n * - iOS: `file:///path/to/Library/Caches/audio_CD5E6C6C-3D9D-4754-9188-D6FAF97D9DF2.wav`\n */\n uri: string | null;\n /**\n * Epoch milliseconds when the microphone stopped, comparable to `Date.now()`.\n * May have a fractional part.\n *\n * Native code records this before it finalizes the file, so\n * `audioend.timestamp - audiostart.timestamp` approximates the recording duration.\n */\n timestamp: number;\n };\n end: null;\n soundstart: null;\n soundend: null;\n languagedetection: LanguageDetectionEvent;\n volumechange: {\n /**\n * A float value between -2 and 10 indicating the volume of the input audio\n *\n * Consider anything below 0 to be inaudible\n */\n value: number;\n };\n};\n\nexport type ExpoSpeechRecognitionOptions = {\n /** [Default: \"en-US\"] The language of the speech recognition */\n lang?: string;\n /** [Default: false] Note for iOS: final results are only available after speech recognition has stopped */\n interimResults?: boolean;\n /** [Default: 5] The maximum number of alternative transcriptions to return. */\n maxAlternatives?: number;\n /**\n * An array of strings that will be used to provide context to the speech recognition engine.\n *\n * On Android, this configures [`EXTRA_BIASING_STRINGS`](https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_BIASING_STRINGS) in the recognizer intent (API level 33+).\n *\n * On iOS, this configures [`SFSpeechRecognitionRequest.contextualStrings`](https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/1649391-contextualstrings).\n */\n contextualStrings?: string[];\n /**\n * [Default: false] Continuous recognition.\n *\n * Not supported on Android 12 and below.\n *\n * If false, the behaviors are the following:\n *\n * - on iOS 17-, recognition will run until no speech is detected for 3 seconds.\n * - on iOS 18+ and Android, recognition will run until a result with `isFinal: true` is received.\n */\n continuous?: boolean;\n /** [Default: false] Prevent device from sending audio over the network. On iOS, if on-device recognition is unavailable for the locale, `start()` emits an error event with the code `not-allowed` instead of falling back to the network.\n *\n * Use `getSupportedLocales()` to verify if the locale is installed on the device prior to enabling this option.\n */\n requiresOnDeviceRecognition?: boolean;\n /**\n * [Default: false] Include punctuation in the recognition results. This applies to full stops and commas.\n *\n * On Android, this configures [`EXTRA_ENABLE_FORMATTING`](https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_FORMATTING) in the recognizer intent (Android 13+, API level 33+).\n *\n * Note for Android: This feature is only verified to work on Android 13+ with on-device speech recognition enabled (i.e. enabling `requiresOnDeviceRecognition` or using the `com.google.android.as` service package)\n *\n * On iOS, this configures [`SFSpeechRecognitionRequest.addsPunctuation`](https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/3930023-addspunctuation).\n */\n addsPunctuation?: boolean;\n /**\n * The package name of the speech recognition service to use.\n * If not provided, the default service will be used.\n *\n * Obtain the supported packages by running `ExpoSpeechRecognitionModule.getSpeechRecognitionServices()`\n *\n * e.g. \"com.google.android.as\" or \"com.samsung.android.bixby.agent\"\n */\n androidRecognitionServicePackage?: string;\n /**\n * Extra options to provide to the Android Recognition intent.\n *\n * For a full list of options, see https://developer.android.com/reference/android/speech/RecognizerIntent\n */\n androidIntentOptions?: Partial<AndroidIntentOptions>;\n /**\n * Audio source options to pass to the recognizer.\n *\n * This option can be used to recognize audio from a local or remote file URI.\n */\n audioSource?: AudioSourceOptions;\n /**\n * Audio recording options for persisting the audio to a local file path.\n */\n recordingOptions?: RecordingOptions;\n /**\n * Default: `\"android.speech.action.RECOGNIZE_SPEECH\"`\n *\n * The kind of intent action\n *\n * Intents:\n *\n * - [`android.speech.action.RECOGNIZE_SPEECH`](https://developer.android.com/reference/android/speech/RecognizerIntent#ACTION_RECOGNIZE_SPEECH) which performs speech recognition (default)\n * - [`android.speech.action.VOICE_SEARCH_HANDS_FREE`](https://developer.android.com/reference/android/speech/RecognizerIntent#ACTION_VOICE_SEARCH_HANDS_FREE) - prompts the user for speech without requiring the user's visual attention or touch input\n * - [`android.speech.action.WEB_SEARCH`](https://developer.android.com/reference/android/speech/RecognizerIntent#ACTION_WEB_SEARCH) - displays a web search result or trigger another type of action based on the user's speech.\n */\n androidIntent?:\n | \"android.speech.action.RECOGNIZE_SPEECH\"\n | \"android.speech.action.VOICE_SEARCH_HANDS_FREE\"\n | \"android.speech.action.WEB_SEARCH\";\n\n /**\n * The hint for the speech recognition task.\n *\n * Default: `\"unspecified\"`\n *\n * Docs: https://developer.apple.com/documentation/speech/sfspeechrecognitiontaskhint\n */\n iosTaskHint?: IOSTaskHintValue;\n\n /**\n * The audio category for the speech recognition task.\n *\n * Use this option to configure the default audio session category and mode prior to starting speech recognition.\n *\n * **Caution:** confirm that the category, options and mode are compatible with the audio source.\n *\n * By default, the audio session category and mode are set to:\n *\n * - category: `playAndRecord`\n * - options: `defaultToSpeaker` and `allowBluetooth`\n * - mode: `measurement`\n *\n * Docs: https://developer.apple.com/documentation/avfaudio/avaudiosession/category\n */\n iosCategory?: SetCategoryOptions;\n\n /**\n * Settings for volume change events.\n */\n volumeChangeEventOptions?: {\n /**\n * Whether to emit volume change events.\n *\n * Default: false\n */\n enabled?: boolean;\n /**\n * Specifies the interval (in milliseconds) to emit `volumechange` events.\n *\n * Default: 100ms on iOS\n *\n * Increasing this value will improve performance\n */\n intervalMillis?: number;\n };\n\n /**\n * [iOS only] Enabling this option will prevent microphone feedback.\n *\n * When enabled, extra signal processing is applied on the incoming audio, and any audio that is coming from the device is taken out.\n *\n * Note: this setting may switch the AVAudioSession mode to \"voiceChat\" and lower the volume of speaker playback\n *\n * (This option will place both input and output nodes in voice processing mode as noted in Apple docs: http://developer.apple.com/videos/play/wwdc2019/510/?time=66)\n */\n iosVoiceProcessingEnabled?: boolean;\n};\n\nexport type IOSTaskHintValue = (typeof TaskHintIOS)[keyof typeof TaskHintIOS];\n\nexport type RecordingOptions = {\n /**\n * Whether to persist the audio to a local file path.\n *\n * Default: false\n */\n persist: boolean;\n /**\n * Default: `FileSystem.CacheDirectory`. This changes the default storage location for the audio file.\n */\n outputDirectory?: string;\n /**\n * Default: `\"recording_${timestamp|uuid}.[wav|caf]\"`. This changes the file name for the audio file.\n */\n outputFileName?: string;\n /**\n * Default: undefined. The sample rate of the output audio file.\n *\n * Only supported on iOS\n *\n * Default sample rate is: 16000 on Android, 44100/48000 on iOS\n */\n outputSampleRate?: number;\n /**\n * Default: undefined. The encoding of the output audio file.\n *\n * Only supported on iOS\n */\n outputEncoding?:\n | \"pcmFormatFloat32\"\n | \"pcmFormatFloat64\"\n | \"pcmFormatInt16\"\n | \"pcmFormatInt32\";\n};\n\nexport type AudioSourceOptions = {\n /**\n * Local audio source URI.\n *\n * e.g. `\"file:///storage/emulated/0/Download/audio.wav\"`\n */\n uri: string;\n /**\n * [Android only] The number of channels in the source audio.\n *\n * Default: 1\n */\n audioChannels?: number;\n /**\n * [Android only] A value from [AudioFormat](https://developer.android.com/reference/android/media/AudioFormat).\n *\n * Use the `AudioEncodingAndroid` enum to get the correct value.\n */\n audioEncoding?: AudioEncodingAndroidValue;\n /**\n * [Android only] Audio sampling rate in Hz.\n *\n * Default: 16000\n */\n sampleRate?: number;\n /**\n * [Android only] The delay for a 4KiB chunk of audio to stream to the speech recognition service.\n *\n * Use this setting to avoid being rate-limited when using network-based recognition.\n *\n * If you're using on-device recognition, you may want to increase this value to avoid unprocessed audio chunks.\n *\n * Default: 50ms for network-based recognition, 15ms for on-device recognition\n */\n chunkDelayMillis?: number;\n};\n\nexport type AudioEncodingAndroidValue =\n (typeof AudioEncodingAndroid)[keyof typeof AudioEncodingAndroid];\n\nexport type AndroidIntentOptions = {\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_CALLING_PACKAGE\n *\n * The extra key used in an intent to the speech recognizer for voice search. Not generally to be used by developers. The system search dialog uses this, for example, to set a calling package for identification by a voice search API. If this extra is set by anyone but the system process, it should be overridden by the voice search implementation.\n */\n EXTRA_CALLING_PACKAGE: string;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_BIASING_DEVICE_CONTEXT\n *\n * Optional boolean to enable biasing towards device context. The recognizer will use the device context to tune the recognition results.\n *\n * Depending on the recognizer implementation, this value may have no effect.\n */\n EXTRA_ENABLE_BIASING_DEVICE_CONTEXT: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_LANGUAGE_DETECTION\n *\n * Optional boolean indicating whether to enable language detection. When enabled, the recognizer will consistently identify the language of the current spoken utterance and provide that info via RecognitionListener#onLanguageDetection(Bundle).\n */\n EXTRA_ENABLE_LANGUAGE_DETECTION: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_LANGUAGE_SWITCH\n *\n * Optional string to enable automatic switching to the language being spoken with the desired sensitivity level, instead of being restricted to a single language. The corresponding language models must be downloaded to support the switch. Otherwise, the recognizer will report an error on a switch failure. The recognizer provides the switch results via RecognitionListener#onLanguageDetection(Bundle).\n *\n * Since detection is a necessary requirement for the language switching, setting this value implicitly enables EXTRA_ENABLE_LANGUAGE_DETECTION.\n *\n * Depending on the recognizer implementation, this value may have no effect.\n */\n EXTRA_ENABLE_LANGUAGE_SWITCH: (typeof RecognizerIntentEnableLanguageSwitch)[keyof typeof RecognizerIntentEnableLanguageSwitch];\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_FORMATTING\n *\n * NOTE: This is also configurable through `addsPunctuation` (which sets `EXTRA_ENABLE_FORMATTING` to \"quality\")\n *\n * [API level 33] Optional string to enable text formatting (e.g. unspoken punctuation (examples: question mark, comma, period, etc.), capitalization, etc.) and specify the optimization strategy. If set, the partial and final result texts will be formatted. Each result list will contain two hypotheses in the order of 1) formatted text 2) raw text.\n *\n */\n EXTRA_ENABLE_FORMATTING: \"latency\" | \"quality\";\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_HIDE_PARTIAL_TRAILING_PUNCTUATION\n *\n * [API level 33] Optional boolean, to be used with EXTRA_ENABLE_FORMATTING, to prevent the recognizer adding punctuation after the last word of the partial results. The default is false.\n */\n EXTRA_HIDE_PARTIAL_TRAILING_PUNCTUATION: boolean;\n /**\n * Optional list of IETF language tags (as defined by BCP 47, e.g. \"en-US\", \"de-DE\").\n *\n * [API level 34] This extra is to be used with EXTRA_ENABLE_LANGUAGE_DETECTION. If set, the recognizer will constrain the language detection output to this list of languages, potentially improving detection accuracy.\n */\n EXTRA_LANGUAGE_DETECTION_ALLOWED_LANGUAGES: string[];\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_MODEL\n *\n * [Default: free_form] The language model to use for speech recognition.\n *\n * Informs the recognizer which speech model to prefer when performing ACTION_RECOGNIZE_SPEECH.\n * The recognizer uses this information to fine tune the results.\n * This extra is required. Activities implementing ACTION_RECOGNIZE_SPEECH may interpret the values as they see fit.\n */\n EXTRA_LANGUAGE_MODEL: (typeof RecognizerIntentExtraLanguageModel)[keyof typeof RecognizerIntentExtraLanguageModel];\n\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_SWITCH_ALLOWED_LANGUAGES\n *\n * [API level 34] Optional list of IETF language tags (as defined by BCP 47, e.g. \"en-US\", \"de-DE\").\n * This extra is to be used with EXTRA_ENABLE_LANGUAGE_SWITCH. If set, the recognizer will apply the auto switch only to these languages, even if the speech models of other languages also exist.\n * The corresponding language models must be downloaded to support the switch. Otherwise, the recognizer will report an error on a switch failure.\n */\n EXTRA_LANGUAGE_SWITCH_ALLOWED_LANGUAGES: string[];\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_SWITCH_INITIAL_ACTIVE_DURATION_TIME_MILLIS\n *\n * [API level 35] Optional integer to use for EXTRA_ENABLE_LANGUAGE_SWITCH. If set, the language switch will only be activated for this value of ms of audio since the START_OF_SPEECH. This could provide a more stable recognition result when the language switch is only required in the beginning of the session.\n */\n EXTRA_LANGUAGE_SWITCH_INITIAL_ACTIVE_DURATION_TIME_MILLIS: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_SWITCH_MAX_SWITCHES\n *\n * [API level 35] Optional integer to use for EXTRA_ENABLE_LANGUAGE_SWITCH. If set, the language switch will be deactivated when LANGUAGE_SWITCH_MAX_SWITCHES reached.\n *\n * Depending on the recognizer implementation, this flag may have no effect.\n */\n EXTRA_LANGUAGE_SWITCH_MAX_SWITCHES: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_MASK_OFFENSIVE_WORDS\n *\n * [API level 33] Optional boolean indicating whether the recognizer should mask the offensive words in recognition results. The Default is true.\n *\n * Constant Value: \"android.speech.extra.MASK_OFFENSIVE_WORDS\"\n */\n EXTRA_MASK_OFFENSIVE_WORDS: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ORIGIN\n *\n * Optional value which can be used to indicate the referer url of a page in which speech was requested. For example, a web browser may choose to provide this for uses of speech on a given page.\n */\n EXTRA_ORIGIN: string;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_PREFER_OFFLINE\n *\n * Optional boolean, to be used with ACTION_RECOGNIZE_SPEECH, ACTION_VOICE_SEARCH_HANDS_FREE, ACTION_WEB_SEARCH to indicate whether to only use an offline speech recognition engine. The default is false, meaning that either network or offline recognition engines may be used.\n *\n * Depending on the recognizer implementation, these values may have no effect.\n */\n EXTRA_PREFER_OFFLINE: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_PROMPT\n *\n * Optional text prompt to show to the user when asking them to speak.\n */\n EXTRA_PROMPT: string;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_REQUEST_WORD_CONFIDENCE\n *\n * [API level 34] Optional boolean indicating whether the recognizer should return the confidence level of each word in the final recognition results.\n */\n EXTRA_REQUEST_WORD_CONFIDENCE: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_REQUEST_WORD_TIMING\n *\n * [API level 34] Optional boolean indicating whether the recognizer should return the timestamp of each word in the final recognition results.\n */\n EXTRA_REQUEST_WORD_TIMING: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SECURE\n *\n * Optional boolean to indicate that a \"hands free\" voice search was performed while the device was in a secure mode. An example of secure mode is when the device's screen lock is active, and it requires some form of authentication to be unlocked. When the device is securely locked, the voice search activity should either restrict the set of voice actions that are permitted, or require some form of secure authentication before proceeding.\n */\n EXTRA_SECURE: boolean;\n /**\n * Optional string to enable segmented session mode of the specified type,\n * which can be `EXTRA_AUDIO_SOURCE`, `EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS` or `EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS`.\n * When segmented session mode is supported by the recognizer implementation and this extra is set,\n * it will return the recognition results in segments via [RecognitionListener#onSegmentResults(Bundle)](https://developer.android.com/reference/android/speech/RecognitionListener#onSegmentResults(android.os.Bundle))\n * and terminate the session with [RecognitionListener#onEndOfSegmentedSession()](https://developer.android.com/reference/android/speech/RecognitionListener#onEndOfSegmentedSession()).\n *\n * When setting this extra, make sure the extra used as the string value here is also set in the same intent with proper value.\n *\n * Depending on the recognizer implementation, this value may have no effect.\n */\n EXTRA_SEGMENTED_SESSION:\n | \"android.speech.extra.AUDIO_SOURCE\"\n | \"android.speech.extras.SPEECH_INPUT_MINIMUM_LENGTH_MILLIS\"\n | \"android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS\";\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS\n *\n * The amount of time that it should take after the recognizer stops hearing speech to consider the input complete hence end the recognition session.\n *\n * Note that it is extremely rare you'd want to specify this value in an intent. Generally, it should be specified only when it is also used as the value for EXTRA_SEGMENTED_SESSION to enable segmented session mode. Note also that certain values may cause undesired or unexpected results - use judiciously!\n *\n * Depending on the recognizer implementation, these values may have no effect.\n *\n */\n EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS\n *\n * Optional integer to indicate the minimum length of the recognition session. The recognizer will not stop recognizing speech before this amount of time.\n *\n * Note that it is extremely rare you'd want to specify this value in an intent. Generally, it should be specified only when it is also used as the value for EXTRA_SEGMENTED_SESSION to enable segmented session mode. Note also that certain values may cause undesired or unexpected results - use judiciously!\n *\n * Depending on the recognizer implementation, these values may have no effect.\n */\n EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS\n *\n * The amount of time that it should take after we stop hearing speech to consider the input possibly complete.\n * This is used to prevent the endpointer cutting off during very short mid-speech pauses.\n * Note that it is extremely rare you'd want to specify this value in an intent.\n * If you don't have a very good reason to change these, you should leave them as they are.\n * Note also that certain values may cause undesired or unexpected results - use judiciously!\n * Additionally, depending on the recognizer implementation, these values may have no effect.\n */\n EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS: number;\n};\n\nexport type ExpoSpeechRecognitionNativeEvents = {\n [K in keyof ExpoSpeechRecognitionNativeEventMap]: (\n event: ExpoSpeechRecognitionNativeEventMap[K],\n ) => void;\n};\n\nexport declare class ExpoSpeechRecognitionModuleType extends NativeModule<ExpoSpeechRecognitionNativeEvents> {\n /**\n * Starts speech recognition.\n */\n start(options: ExpoSpeechRecognitionOptions): void;\n /**\n * Stops speech recognition and attempts to return a final result (through the `result` event).\n */\n stop(): void;\n /**\n * Cancels speech recognition immediately without returning a final result.\n */\n abort(): void;\n /**\n * Presents a dialog to the user to request permissions for using speech recognition and the microphone.\n *\n * For Android, this will request RECORD_AUDIO permission.\n *\n * For iOS, this will request microphone and speech recognition permissions.\n * Once a user has granted (or denied) permissions by responding to the original permission request dialog,\n * the only way that the permissions can be changed is by the user themselves using the device settings app.\n */\n requestPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;\n /**\n * Returns the current permission status for speech recognition and the microphone.\n *\n * You may also use `getMicrophonePermissionsAsync` and `getSpeechRecognizerPermissionsAsync` to get the permissions separately.\n */\n getPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;\n /**\n * Returns the current permission status for the microphone.\n */\n getMicrophonePermissionsAsync(): Promise<PermissionResponse>;\n /**\n * Presents a dialog to the user to request permissions for using the microphone.\n *\n * For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,\n * the only way that the permissions can be changed is by the user themselves using the device settings app.\n */\n requestMicrophonePermissionsAsync(): Promise<PermissionResponse>;\n /**\n * Returns the current permission status for speech recognition.\n */\n getSpeechRecognizerPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;\n /**\n * [iOS only] Presents a dialog to the user to request permissions for using the speech recognizer.\n * This permission is required when `requiresOnDeviceRecognition` is disabled (i.e. network-based recognition)\n *\n * For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,\n * the only way that the permissions can be changed is by the user themselves using the device settings app.\n */\n requestSpeechRecognizerPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;\n /**\n * Returns an array of locales supported by the speech recognizer.\n *\n * Not supported on Android 12 and below (API level 31), this will return an empty array of locales.\n *\n * @throws {\"package_not_found\"} If the service package is not found.\n * @throws {\"error_[number]\"} If there was an error retrieving the supported locales.\n */\n getSupportedLocales(options: {\n /**\n * The package name of the speech recognition service to use.\n *\n * e.g. \"com.google.android.as\" or \"com.samsung.android.bixby.agent\"\n *\n * Warning: the service package (such as Bixby) may not be able to return any results.\n */\n androidRecognitionServicePackage?: string;\n }): Promise<{\n /**\n * All supported languages on the device. This includes both installed and supported languages.\n */\n locales: string[];\n /**\n * These languages are installed on to the device for offline use.\n *\n * This will likely be an empty array if the service package is not \"com.google.android.as\"\n */\n installedLocales: string[];\n }>;\n /**\n * [Android only] Returns an array of package names of speech recognition services that are available on the device.\n *\n * List of all available services as bundle identifiers, e.g. [\"com.google.android.as\", \"com.google.android.tts\"]\n */\n getSpeechRecognitionServices(): string[];\n /**\n * [Android only] Returns the default voice recognition service on the device.\n *\n * @returns empty string if no service is found, or not Android\n */\n getDefaultRecognitionService(): {\n /** e.g. \"com.google.android.tts\" or \"com.google.android.googlequicksearchbox\" */\n packageName: string;\n };\n /**\n * [Android only] Returns the default voice recognition service on the device.\n *\n * e.g. \"com.google.android.googlequicksearchbox\" or \"com.samsung.android.bixby.agent\"\n *\n * @returns empty string if no service is found, or not Android\n */\n getAssistantService(): {\n /** e.g. \"com.google.android.googlequicksearchbox\" or \"com.samsung.android.bixby.agent\" */\n packageName: string;\n };\n /**\n * Whether the on-device speech recognition is available on the device.\n */\n supportsOnDeviceRecognition(): boolean;\n /**\n * Whether the recording feature is available on the device.\n *\n * This mostly applies to Android devices, to check if it's greater than Android 13.\n */\n supportsRecording(): boolean;\n /**\n * Whether on-device speech recognition is available.\n *\n * If this method returns false, `start()` will fail and emit an error event with the code `service-not-allowed` or `language-not-supported`.\n */\n isRecognitionAvailable(): boolean;\n\n /**\n * Downloads the offline model for the specified locale.\n * Note: this is only supported on Android 13 and above.\n */\n androidTriggerOfflineModelDownload(options: {\n /** The locale to download the model for, e.g. \"en-US\" */\n locale: string;\n }): Promise<{\n /**\n * On Android 13, \"opened_dialog\" - the model download dialog was shown (fire-and-forget, no events emitted).\n * On Android 14+, \"download_success\" if the model downloaded immediately,\n * or \"download_scheduled\" if the download was queued (e.g., waiting for WiFi).\n */\n status: \"download_success\" | \"opened_dialog\" | \"download_scheduled\";\n message: string;\n }>;\n /**\n * [iOS only] For advanced use cases, you may use this function to set the audio session category and mode.\n *\n * See: https://developer.apple.com/documentation/avfaudio/avaudiosession/1771734-setcategory\n */\n setCategoryIOS(options: SetCategoryOptions): void;\n\n /**\n * [iOS only] Returns the current audio session category and options.\n *\n * See:\n * - [AVAudioSession.Category](https://developer.apple.com/documentation/avfaudio/avaudiosession/category)\n * - [AVAudioSession.CategoryOptions](https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions)\n * - [AVAudioSession.Mode](https://developer.apple.com/documentation/avfaudio/avaudiosession/mode)\n */\n getAudioSessionCategoryAndOptionsIOS(): {\n category: AVAudioSessionCategoryValue;\n categoryOptions: AVAudioSessionCategoryOptionsValue[];\n mode: AVAudioSessionModeValue;\n };\n /**\n * [iOS only] Sets the shared audio session active state.\n *\n * Calls the following on iOS: `AVAudioSession.sharedInstance().setActive(value, options)`\n *\n * See: https://developer.apple.com/documentation/avfaudio/avaudiosession/1616627-setactive\n */\n setAudioSessionActiveIOS(\n value: boolean,\n options?: {\n /** [Default: true] Whether to notify other audio sessions when the active state changes. */\n notifyOthersOnDeactivation: boolean;\n },\n ): void;\n /**\n * Returns the current state of the speech recognizer.\n */\n getStateAsync(): Promise<SpeechRecognitionState>;\n}\n\nexport type SetCategoryOptions = {\n category: AVAudioSessionCategoryValue;\n categoryOptions: AVAudioSessionCategoryOptionsValue[];\n mode?: AVAudioSessionModeValue;\n};\n\ntype SpeechRecognitionState =\n | \"inactive\"\n | \"starting\"\n | \"recognizing\"\n | \"stopping\";\n\n/**\n * [iOS only] See: [AVAudioSession.CategoryOptions](https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions)\n *\n * Use the `AVAudioSessionCategoryOptions` enum to get the correct value.\n */\nexport type AVAudioSessionCategoryOptionsValue =\n (typeof AVAudioSessionCategoryOptions)[keyof typeof AVAudioSessionCategoryOptions];\n\n/**\n * [iOS only] See: [AVAudioSession.Mode](https://developer.apple.com/documentation/avfaudio/avaudiosession/mode)\n *\n * Use the `AVAudioSessionMode` enum to get the correct value.\n */\nexport type AVAudioSessionModeValue =\n (typeof AVAudioSessionMode)[keyof typeof AVAudioSessionMode];\n"]}
|
|
1
|
+
{"version":3,"file":"ExpoSpeechRecognitionModule.types.js","sourceRoot":"","sources":["../src/ExpoSpeechRecognitionModule.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionResponse } from \"expo-modules-core\";\nimport type { NativeModule } from \"expo\";\n\nexport type ExpoSpeechRecognitionPermissionResponse = PermissionResponse & {\n /**\n * Whether the speech recognition is restricted by Content & Privacy Restrictions.\n *\n * This value corresponds to the `restricted` enum of `SFSpeechRecognizer.authorizationStatus()`.\n *\n * This is only available on iOS.\n */\n restricted?: boolean;\n};\n\nimport type {\n AudioEncodingAndroid,\n AVAudioSessionCategory,\n AVAudioSessionCategoryOptions,\n AVAudioSessionMode,\n RecognizerIntentEnableLanguageSwitch,\n RecognizerIntentExtraLanguageModel,\n TaskHintIOS,\n} from \"./constants\";\n\nexport type AVAudioSessionCategoryValue =\n (typeof AVAudioSessionCategory)[keyof typeof AVAudioSessionCategory];\n\nexport type ExpoSpeechRecognitionResult = {\n transcript: string;\n /**\n * Value ranging between between 0.0, 1.0, and -1 (unavailable) indicating transcript confidence.\n */\n confidence: number;\n /**\n * An array of transcription segments that represent the parts of the transcription, as identified by the speech recognizer.\n *\n * Notes for Android:\n *\n * - This is only available for SDK 34+ (Android 14+)\n * - This is only verified to work with the `com.google.android.as` service (using on device speech recognition)\n * - Segments are only available during the final result\n * - The segment parts are split up by words.\n * - The segments are only available for the first transcript\n * - Segment confidences currently return as -1 (unavailable)\n *\n * Notes for iOS:\n *\n * - The confidence value will be 0 on partial results\n */\n segments: ExpoSpeechRecognitionResultSegment[];\n};\n\nexport type ExpoSpeechRecognitionResultSegment = {\n /** The start timestamp of the utterance, e.g. 1000 */\n startTimeMillis: number;\n /** The end timestamp of the utterance, e.g. 1500 */\n endTimeMillis: number;\n /** The text portion of the transcript, e.g. \"Hello world\" */\n segment: string;\n /** Value ranging between between 0.0, 1.0, and -1 (unavailable) indicating the confidence of the specific segment */\n confidence: number;\n};\n\n/** Fired when there's a speech result. The result may be partial or final */\nexport type ExpoSpeechRecognitionResultEvent = {\n isFinal: boolean;\n results: ExpoSpeechRecognitionResult[];\n};\n\nexport type ExpoSpeechRecognitionErrorCode =\n /** The user called `ExpoSpeechRecognitionModule.abort()`. */\n | \"aborted\"\n /** Audio recording error. */\n | \"audio-capture\"\n /** (iOS) The audio session was interrupted (phone call, Siri, alarm). */\n | \"interrupted\"\n /** There was an error in the speech recognition grammar or semantic tags, or the chosen grammar format or semantic tag format was unsupported. */\n | \"bad-grammar\"\n /** Locale is not supported by the speech recognizer. */\n | \"language-not-supported\"\n /** Network communication required for completing the recognition failed. */\n | \"network\"\n /** No final speech was detected. */\n | \"no-speech\"\n /** Permission to use speech recognition or microphone was not granted. */\n | \"not-allowed\"\n /** Recognizer is unavailable. */\n | \"service-not-allowed\"\n // Extra codes (not part of the spec)\n /** The recognizer is busy and cannot accept any new recognition requests. */\n | \"busy\"\n /** (Android only) An unknown client-side error occurred. */\n | \"client\"\n /** (Android) No speech input. */\n | \"speech-timeout\"\n /** (Android 12+) Too many requests from the same client. */\n | \"too-many-requests\"\n /** (Android) Unknown error */\n | \"unknown\";\n\nexport type ExpoSpeechRecognitionErrorEvent = {\n error: ExpoSpeechRecognitionErrorCode;\n message: string;\n /**\n * The underlying native error code from the platform-specific speech recognition service.\n *\n * - On Android: Maps to SpeechRecognizer error constants (e.g., ERROR_AUDIO = 3)\n * - Value of -1 indicates a generic/unknown error or when native code is not available\n *\n * Usually you won't need this field, but it can be useful for debugging purposes.\n */\n code?: number;\n};\n\nexport type LanguageDetectionEvent = {\n /** The language that was detected, in BCP-47 format. e.g. \"en-US\", \"de-DE\" */\n detectedLanguage: string;\n /** The confidence of the detected language. A value ranging between 0.0 and 1.0.\n *\n * Values range from:\n *\n * - 1.0 (highly confident)\n * - 0.8 (confident)\n * - 0.5 (not confident)\n * - 0.0 (unknown)\n */\n confidence: number;\n /** The alternative locales for the same language, in BCP-47 format. e.g. [\"en-US\", \"en-GB\"] */\n topLocaleAlternatives: string[];\n};\n\n/**\n * Events that are dispatched from the native side\n */\nexport type ExpoSpeechRecognitionNativeEventMap = {\n result: ExpoSpeechRecognitionResultEvent;\n error: ExpoSpeechRecognitionErrorEvent;\n start: null;\n speechstart: null;\n speechend: null;\n /** A final result is returned with no significant recognition */\n nomatch: null;\n /** Audio capturing had started */\n audiostart: {\n /**\n * The uri is set when `recordingOptions.persist` is enabled.\n * Do not attempt to use this file until the `audioend` event is emitted.\n *\n * Example URIs:\n *\n * - Android: `file:///data/user/0/expo.modules.speechrecognition.example/cache/recording_1720678500903.wav`\n * - iOS: `file:///path/to/Library/Caches/audio_CD5E6C6C-3D9D-4754-9188-D6FAF97D9DF2.wav`\n */\n uri: string | null;\n /**\n * Epoch milliseconds when audio capturing started, comparable to `Date.now()`.\n * May have a fractional part.\n *\n * With `recordingOptions.persist`, it marks the start of the file to within tens of milliseconds.\n *\n * iOS: an audio route change mid-recording, such as connecting headphones, leaves a gap in the file.\n * Positions after the gap drift from this timestamp.\n */\n timestamp: number;\n };\n /** Audio capturing had ended */\n audioend: {\n /**\n * The uri is set when `recordingOptions.persist` is enabled.\n *\n * Example URIs:\n *\n * - Android: `file:///data/user/0/expo.modules.speechrecognition.example/cache/recording_1720678500903.wav`\n * - iOS: `file:///path/to/Library/Caches/audio_CD5E6C6C-3D9D-4754-9188-D6FAF97D9DF2.wav`\n */\n uri: string | null;\n /**\n * Epoch milliseconds when the microphone stopped, comparable to `Date.now()`.\n * May have a fractional part.\n *\n * Native code records this before it finalizes the file, so\n * `audioend.timestamp - audiostart.timestamp` approximates the recording duration.\n */\n timestamp: number;\n };\n end: null;\n soundstart: null;\n soundend: null;\n languagedetection: LanguageDetectionEvent;\n volumechange: {\n /**\n * A float value between -2 and 10 indicating the volume of the input audio\n *\n * Consider anything below 0 to be inaudible\n */\n value: number;\n };\n};\n\nexport type ExpoSpeechRecognitionOptions = {\n /** [Default: \"en-US\"] The language of the speech recognition */\n lang?: string;\n /** [Default: false] Note for iOS: final results are only available after speech recognition has stopped */\n interimResults?: boolean;\n /** [Default: 5] The maximum number of alternative transcriptions to return. */\n maxAlternatives?: number;\n /**\n * An array of strings that will be used to provide context to the speech recognition engine.\n *\n * On Android, this configures [`EXTRA_BIASING_STRINGS`](https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_BIASING_STRINGS) in the recognizer intent (API level 33+).\n *\n * On iOS, this configures [`SFSpeechRecognitionRequest.contextualStrings`](https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/1649391-contextualstrings).\n */\n contextualStrings?: string[];\n /**\n * [Default: false] Continuous recognition.\n *\n * Not supported on Android 12 and below.\n *\n * If false, the behaviors are the following:\n *\n * - on iOS 17-, recognition will run until no speech is detected for 3 seconds.\n * - on iOS 18+ and Android, recognition will run until a result with `isFinal: true` is received.\n */\n continuous?: boolean;\n /** [Default: false] Prevent device from sending audio over the network. On iOS, if on-device recognition is unavailable for the locale, `start()` emits an error event with the code `not-allowed` instead of falling back to the network.\n *\n * Use `getSupportedLocales()` to verify if the locale is installed on the device prior to enabling this option.\n */\n requiresOnDeviceRecognition?: boolean;\n /**\n * [Default: false] Include punctuation in the recognition results. This applies to full stops and commas.\n *\n * On Android, this configures [`EXTRA_ENABLE_FORMATTING`](https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_FORMATTING) in the recognizer intent (Android 13+, API level 33+).\n *\n * Note for Android: This feature is only verified to work on Android 13+ with on-device speech recognition enabled (i.e. enabling `requiresOnDeviceRecognition` or using the `com.google.android.as` service package)\n *\n * On iOS, this configures [`SFSpeechRecognitionRequest.addsPunctuation`](https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/3930023-addspunctuation).\n */\n addsPunctuation?: boolean;\n /**\n * The package name of the speech recognition service to use.\n * If not provided, the default service will be used.\n *\n * Obtain the supported packages by running `ExpoSpeechRecognitionModule.getSpeechRecognitionServices()`\n *\n * e.g. \"com.google.android.as\" or \"com.samsung.android.bixby.agent\"\n */\n androidRecognitionServicePackage?: string;\n /**\n * [Android only] Request audio focus while recognizing from the microphone.\n *\n * Other apps (e.g. music or podcast players) pause their playback when recognition starts,\n * and resume it when recognition ends.\n *\n * This requests [`AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE`](https://developer.android.com/reference/android/media/AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE),\n * the focus type Android recommends for speech recognition. It has no effect when `audioSource` is set.\n *\n * This is mainly useful with `continuous` or `recordingOptions.persist`. Without those,\n * some recognition services (e.g. Google's) already request audio focus themselves.\n *\n * The focus is held for the duration of a session, so if you call `start()` again from the \"end\" event,\n * other apps may briefly resume their playback between sessions.\n *\n * On iOS, use `iosCategory` to control how other apps' audio is handled.\n *\n * Default: false\n */\n androidAudioFocus?: boolean;\n /**\n * Extra options to provide to the Android Recognition intent.\n *\n * For a full list of options, see https://developer.android.com/reference/android/speech/RecognizerIntent\n */\n androidIntentOptions?: Partial<AndroidIntentOptions>;\n /**\n * Audio source options to pass to the recognizer.\n *\n * This option can be used to recognize audio from a local or remote file URI.\n */\n audioSource?: AudioSourceOptions;\n /**\n * Audio recording options for persisting the audio to a local file path.\n */\n recordingOptions?: RecordingOptions;\n /**\n * Default: `\"android.speech.action.RECOGNIZE_SPEECH\"`\n *\n * The kind of intent action\n *\n * Intents:\n *\n * - [`android.speech.action.RECOGNIZE_SPEECH`](https://developer.android.com/reference/android/speech/RecognizerIntent#ACTION_RECOGNIZE_SPEECH) which performs speech recognition (default)\n * - [`android.speech.action.VOICE_SEARCH_HANDS_FREE`](https://developer.android.com/reference/android/speech/RecognizerIntent#ACTION_VOICE_SEARCH_HANDS_FREE) - prompts the user for speech without requiring the user's visual attention or touch input\n * - [`android.speech.action.WEB_SEARCH`](https://developer.android.com/reference/android/speech/RecognizerIntent#ACTION_WEB_SEARCH) - displays a web search result or trigger another type of action based on the user's speech.\n */\n androidIntent?:\n | \"android.speech.action.RECOGNIZE_SPEECH\"\n | \"android.speech.action.VOICE_SEARCH_HANDS_FREE\"\n | \"android.speech.action.WEB_SEARCH\";\n\n /**\n * The hint for the speech recognition task.\n *\n * Default: `\"unspecified\"`\n *\n * Docs: https://developer.apple.com/documentation/speech/sfspeechrecognitiontaskhint\n */\n iosTaskHint?: IOSTaskHintValue;\n\n /**\n * The audio category for the speech recognition task.\n *\n * Use this option to configure the default audio session category and mode prior to starting speech recognition.\n *\n * **Caution:** confirm that the category, options and mode are compatible with the audio source.\n *\n * By default, the audio session category and mode are set to:\n *\n * - category: `playAndRecord`\n * - options: `defaultToSpeaker` and `allowBluetooth`\n * - mode: `measurement`\n *\n * Docs: https://developer.apple.com/documentation/avfaudio/avaudiosession/category\n */\n iosCategory?: SetCategoryOptions;\n\n /**\n * Settings for volume change events.\n */\n volumeChangeEventOptions?: {\n /**\n * Whether to emit volume change events.\n *\n * Default: false\n */\n enabled?: boolean;\n /**\n * Specifies the interval (in milliseconds) to emit `volumechange` events.\n *\n * Default: 100ms on iOS\n *\n * Increasing this value will improve performance\n */\n intervalMillis?: number;\n };\n\n /**\n * [iOS only] Enabling this option will prevent microphone feedback.\n *\n * When enabled, extra signal processing is applied on the incoming audio, and any audio that is coming from the device is taken out.\n *\n * Note: this setting may switch the AVAudioSession mode to \"voiceChat\" and lower the volume of speaker playback\n *\n * (This option will place both input and output nodes in voice processing mode as noted in Apple docs: http://developer.apple.com/videos/play/wwdc2019/510/?time=66)\n */\n iosVoiceProcessingEnabled?: boolean;\n};\n\nexport type IOSTaskHintValue = (typeof TaskHintIOS)[keyof typeof TaskHintIOS];\n\nexport type RecordingOptions = {\n /**\n * Whether to persist the audio to a local file path.\n *\n * Default: false\n */\n persist: boolean;\n /**\n * Default: `FileSystem.CacheDirectory`. This changes the default storage location for the audio file.\n */\n outputDirectory?: string;\n /**\n * Default: `\"recording_${timestamp|uuid}.[wav|caf]\"`. This changes the file name for the audio file.\n */\n outputFileName?: string;\n /**\n * Default: undefined. The sample rate of the output audio file.\n *\n * Only supported on iOS\n *\n * Default sample rate is: 16000 on Android, 44100/48000 on iOS\n */\n outputSampleRate?: number;\n /**\n * Default: undefined. The encoding of the output audio file.\n *\n * Only supported on iOS\n */\n outputEncoding?:\n | \"pcmFormatFloat32\"\n | \"pcmFormatFloat64\"\n | \"pcmFormatInt16\"\n | \"pcmFormatInt32\";\n};\n\nexport type AudioSourceOptions = {\n /**\n * Local audio source URI.\n *\n * e.g. `\"file:///storage/emulated/0/Download/audio.wav\"`\n */\n uri: string;\n /**\n * [Android only] The number of channels in the source audio.\n *\n * Default: 1\n */\n audioChannels?: number;\n /**\n * [Android only] A value from [AudioFormat](https://developer.android.com/reference/android/media/AudioFormat).\n *\n * Use the `AudioEncodingAndroid` enum to get the correct value.\n */\n audioEncoding?: AudioEncodingAndroidValue;\n /**\n * [Android only] Audio sampling rate in Hz.\n *\n * Default: 16000\n */\n sampleRate?: number;\n /**\n * [Android only] The delay for a 4KiB chunk of audio to stream to the speech recognition service.\n *\n * Use this setting to avoid being rate-limited when using network-based recognition.\n *\n * If you're using on-device recognition, you may want to increase this value to avoid unprocessed audio chunks.\n *\n * Default: 50ms for network-based recognition, 15ms for on-device recognition\n */\n chunkDelayMillis?: number;\n};\n\nexport type AudioEncodingAndroidValue =\n (typeof AudioEncodingAndroid)[keyof typeof AudioEncodingAndroid];\n\nexport type AndroidIntentOptions = {\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_CALLING_PACKAGE\n *\n * The extra key used in an intent to the speech recognizer for voice search. Not generally to be used by developers. The system search dialog uses this, for example, to set a calling package for identification by a voice search API. If this extra is set by anyone but the system process, it should be overridden by the voice search implementation.\n */\n EXTRA_CALLING_PACKAGE: string;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_BIASING_DEVICE_CONTEXT\n *\n * Optional boolean to enable biasing towards device context. The recognizer will use the device context to tune the recognition results.\n *\n * Depending on the recognizer implementation, this value may have no effect.\n */\n EXTRA_ENABLE_BIASING_DEVICE_CONTEXT: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_LANGUAGE_DETECTION\n *\n * Optional boolean indicating whether to enable language detection. When enabled, the recognizer will consistently identify the language of the current spoken utterance and provide that info via RecognitionListener#onLanguageDetection(Bundle).\n */\n EXTRA_ENABLE_LANGUAGE_DETECTION: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_LANGUAGE_SWITCH\n *\n * Optional string to enable automatic switching to the language being spoken with the desired sensitivity level, instead of being restricted to a single language. The corresponding language models must be downloaded to support the switch. Otherwise, the recognizer will report an error on a switch failure. The recognizer provides the switch results via RecognitionListener#onLanguageDetection(Bundle).\n *\n * Since detection is a necessary requirement for the language switching, setting this value implicitly enables EXTRA_ENABLE_LANGUAGE_DETECTION.\n *\n * Depending on the recognizer implementation, this value may have no effect.\n */\n EXTRA_ENABLE_LANGUAGE_SWITCH: (typeof RecognizerIntentEnableLanguageSwitch)[keyof typeof RecognizerIntentEnableLanguageSwitch];\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_FORMATTING\n *\n * NOTE: This is also configurable through `addsPunctuation` (which sets `EXTRA_ENABLE_FORMATTING` to \"quality\")\n *\n * [API level 33] Optional string to enable text formatting (e.g. unspoken punctuation (examples: question mark, comma, period, etc.), capitalization, etc.) and specify the optimization strategy. If set, the partial and final result texts will be formatted. Each result list will contain two hypotheses in the order of 1) formatted text 2) raw text.\n *\n */\n EXTRA_ENABLE_FORMATTING: \"latency\" | \"quality\";\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_HIDE_PARTIAL_TRAILING_PUNCTUATION\n *\n * [API level 33] Optional boolean, to be used with EXTRA_ENABLE_FORMATTING, to prevent the recognizer adding punctuation after the last word of the partial results. The default is false.\n */\n EXTRA_HIDE_PARTIAL_TRAILING_PUNCTUATION: boolean;\n /**\n * Optional list of IETF language tags (as defined by BCP 47, e.g. \"en-US\", \"de-DE\").\n *\n * [API level 34] This extra is to be used with EXTRA_ENABLE_LANGUAGE_DETECTION. If set, the recognizer will constrain the language detection output to this list of languages, potentially improving detection accuracy.\n */\n EXTRA_LANGUAGE_DETECTION_ALLOWED_LANGUAGES: string[];\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_MODEL\n *\n * [Default: free_form] The language model to use for speech recognition.\n *\n * Informs the recognizer which speech model to prefer when performing ACTION_RECOGNIZE_SPEECH.\n * The recognizer uses this information to fine tune the results.\n * This extra is required. Activities implementing ACTION_RECOGNIZE_SPEECH may interpret the values as they see fit.\n */\n EXTRA_LANGUAGE_MODEL: (typeof RecognizerIntentExtraLanguageModel)[keyof typeof RecognizerIntentExtraLanguageModel];\n\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_SWITCH_ALLOWED_LANGUAGES\n *\n * [API level 34] Optional list of IETF language tags (as defined by BCP 47, e.g. \"en-US\", \"de-DE\").\n * This extra is to be used with EXTRA_ENABLE_LANGUAGE_SWITCH. If set, the recognizer will apply the auto switch only to these languages, even if the speech models of other languages also exist.\n * The corresponding language models must be downloaded to support the switch. Otherwise, the recognizer will report an error on a switch failure.\n */\n EXTRA_LANGUAGE_SWITCH_ALLOWED_LANGUAGES: string[];\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_SWITCH_INITIAL_ACTIVE_DURATION_TIME_MILLIS\n *\n * [API level 35] Optional integer to use for EXTRA_ENABLE_LANGUAGE_SWITCH. If set, the language switch will only be activated for this value of ms of audio since the START_OF_SPEECH. This could provide a more stable recognition result when the language switch is only required in the beginning of the session.\n */\n EXTRA_LANGUAGE_SWITCH_INITIAL_ACTIVE_DURATION_TIME_MILLIS: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_SWITCH_MAX_SWITCHES\n *\n * [API level 35] Optional integer to use for EXTRA_ENABLE_LANGUAGE_SWITCH. If set, the language switch will be deactivated when LANGUAGE_SWITCH_MAX_SWITCHES reached.\n *\n * Depending on the recognizer implementation, this flag may have no effect.\n */\n EXTRA_LANGUAGE_SWITCH_MAX_SWITCHES: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_MASK_OFFENSIVE_WORDS\n *\n * [API level 33] Optional boolean indicating whether the recognizer should mask the offensive words in recognition results. The Default is true.\n *\n * Constant Value: \"android.speech.extra.MASK_OFFENSIVE_WORDS\"\n */\n EXTRA_MASK_OFFENSIVE_WORDS: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ORIGIN\n *\n * Optional value which can be used to indicate the referer url of a page in which speech was requested. For example, a web browser may choose to provide this for uses of speech on a given page.\n */\n EXTRA_ORIGIN: string;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_PREFER_OFFLINE\n *\n * Optional boolean, to be used with ACTION_RECOGNIZE_SPEECH, ACTION_VOICE_SEARCH_HANDS_FREE, ACTION_WEB_SEARCH to indicate whether to only use an offline speech recognition engine. The default is false, meaning that either network or offline recognition engines may be used.\n *\n * Depending on the recognizer implementation, these values may have no effect.\n */\n EXTRA_PREFER_OFFLINE: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_PROMPT\n *\n * Optional text prompt to show to the user when asking them to speak.\n */\n EXTRA_PROMPT: string;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_REQUEST_WORD_CONFIDENCE\n *\n * [API level 34] Optional boolean indicating whether the recognizer should return the confidence level of each word in the final recognition results.\n */\n EXTRA_REQUEST_WORD_CONFIDENCE: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_REQUEST_WORD_TIMING\n *\n * [API level 34] Optional boolean indicating whether the recognizer should return the timestamp of each word in the final recognition results.\n */\n EXTRA_REQUEST_WORD_TIMING: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SECURE\n *\n * Optional boolean to indicate that a \"hands free\" voice search was performed while the device was in a secure mode. An example of secure mode is when the device's screen lock is active, and it requires some form of authentication to be unlocked. When the device is securely locked, the voice search activity should either restrict the set of voice actions that are permitted, or require some form of secure authentication before proceeding.\n */\n EXTRA_SECURE: boolean;\n /**\n * Optional string to enable segmented session mode of the specified type,\n * which can be `EXTRA_AUDIO_SOURCE`, `EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS` or `EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS`.\n * When segmented session mode is supported by the recognizer implementation and this extra is set,\n * it will return the recognition results in segments via [RecognitionListener#onSegmentResults(Bundle)](https://developer.android.com/reference/android/speech/RecognitionListener#onSegmentResults(android.os.Bundle))\n * and terminate the session with [RecognitionListener#onEndOfSegmentedSession()](https://developer.android.com/reference/android/speech/RecognitionListener#onEndOfSegmentedSession()).\n *\n * When setting this extra, make sure the extra used as the string value here is also set in the same intent with proper value.\n *\n * Depending on the recognizer implementation, this value may have no effect.\n */\n EXTRA_SEGMENTED_SESSION:\n | \"android.speech.extra.AUDIO_SOURCE\"\n | \"android.speech.extras.SPEECH_INPUT_MINIMUM_LENGTH_MILLIS\"\n | \"android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS\";\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS\n *\n * The amount of time that it should take after the recognizer stops hearing speech to consider the input complete hence end the recognition session.\n *\n * Note that it is extremely rare you'd want to specify this value in an intent. Generally, it should be specified only when it is also used as the value for EXTRA_SEGMENTED_SESSION to enable segmented session mode. Note also that certain values may cause undesired or unexpected results - use judiciously!\n *\n * Depending on the recognizer implementation, these values may have no effect.\n *\n */\n EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS\n *\n * Optional integer to indicate the minimum length of the recognition session. The recognizer will not stop recognizing speech before this amount of time.\n *\n * Note that it is extremely rare you'd want to specify this value in an intent. Generally, it should be specified only when it is also used as the value for EXTRA_SEGMENTED_SESSION to enable segmented session mode. Note also that certain values may cause undesired or unexpected results - use judiciously!\n *\n * Depending on the recognizer implementation, these values may have no effect.\n */\n EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS\n *\n * The amount of time that it should take after we stop hearing speech to consider the input possibly complete.\n * This is used to prevent the endpointer cutting off during very short mid-speech pauses.\n * Note that it is extremely rare you'd want to specify this value in an intent.\n * If you don't have a very good reason to change these, you should leave them as they are.\n * Note also that certain values may cause undesired or unexpected results - use judiciously!\n * Additionally, depending on the recognizer implementation, these values may have no effect.\n */\n EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS: number;\n};\n\nexport type ExpoSpeechRecognitionNativeEvents = {\n [K in keyof ExpoSpeechRecognitionNativeEventMap]: (\n event: ExpoSpeechRecognitionNativeEventMap[K],\n ) => void;\n};\n\nexport declare class ExpoSpeechRecognitionModuleType extends NativeModule<ExpoSpeechRecognitionNativeEvents> {\n /**\n * Starts speech recognition.\n */\n start(options: ExpoSpeechRecognitionOptions): void;\n /**\n * Stops speech recognition and attempts to return a final result (through the `result` event).\n */\n stop(): void;\n /**\n * Cancels speech recognition immediately without returning a final result.\n */\n abort(): void;\n /**\n * Presents a dialog to the user to request permissions for using speech recognition and the microphone.\n *\n * For Android, this will request RECORD_AUDIO permission.\n *\n * For iOS, this will request microphone and speech recognition permissions.\n * Once a user has granted (or denied) permissions by responding to the original permission request dialog,\n * the only way that the permissions can be changed is by the user themselves using the device settings app.\n */\n requestPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;\n /**\n * Returns the current permission status for speech recognition and the microphone.\n *\n * You may also use `getMicrophonePermissionsAsync` and `getSpeechRecognizerPermissionsAsync` to get the permissions separately.\n */\n getPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;\n /**\n * Returns the current permission status for the microphone.\n */\n getMicrophonePermissionsAsync(): Promise<PermissionResponse>;\n /**\n * Presents a dialog to the user to request permissions for using the microphone.\n *\n * For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,\n * the only way that the permissions can be changed is by the user themselves using the device settings app.\n */\n requestMicrophonePermissionsAsync(): Promise<PermissionResponse>;\n /**\n * Returns the current permission status for speech recognition.\n */\n getSpeechRecognizerPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;\n /**\n * [iOS only] Presents a dialog to the user to request permissions for using the speech recognizer.\n * This permission is required when `requiresOnDeviceRecognition` is disabled (i.e. network-based recognition)\n *\n * For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,\n * the only way that the permissions can be changed is by the user themselves using the device settings app.\n */\n requestSpeechRecognizerPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;\n /**\n * Returns an array of locales supported by the speech recognizer.\n *\n * Not supported on Android 12 and below (API level 31), this will return an empty array of locales.\n *\n * @throws {\"package_not_found\"} If the service package is not found.\n * @throws {\"error_[number]\"} If there was an error retrieving the supported locales.\n */\n getSupportedLocales(options: {\n /**\n * The package name of the speech recognition service to use.\n *\n * e.g. \"com.google.android.as\" or \"com.samsung.android.bixby.agent\"\n *\n * Warning: the service package (such as Bixby) may not be able to return any results.\n */\n androidRecognitionServicePackage?: string;\n }): Promise<{\n /**\n * All supported languages on the device. This includes both installed and supported languages.\n */\n locales: string[];\n /**\n * These languages are installed on to the device for offline use.\n *\n * This will likely be an empty array if the service package is not \"com.google.android.as\"\n */\n installedLocales: string[];\n }>;\n /**\n * [Android only] Returns an array of package names of speech recognition services that are available on the device.\n *\n * List of all available services as bundle identifiers, e.g. [\"com.google.android.as\", \"com.google.android.tts\"]\n */\n getSpeechRecognitionServices(): string[];\n /**\n * [Android only] Returns the default voice recognition service on the device.\n *\n * @returns empty string if no service is found, or not Android\n */\n getDefaultRecognitionService(): {\n /** e.g. \"com.google.android.tts\" or \"com.google.android.googlequicksearchbox\" */\n packageName: string;\n };\n /**\n * [Android only] Returns the default voice recognition service on the device.\n *\n * e.g. \"com.google.android.googlequicksearchbox\" or \"com.samsung.android.bixby.agent\"\n *\n * @returns empty string if no service is found, or not Android\n */\n getAssistantService(): {\n /** e.g. \"com.google.android.googlequicksearchbox\" or \"com.samsung.android.bixby.agent\" */\n packageName: string;\n };\n /**\n * Whether the on-device speech recognition is available on the device.\n */\n supportsOnDeviceRecognition(): boolean;\n /**\n * Whether the recording feature is available on the device.\n *\n * This mostly applies to Android devices, to check if it's greater than Android 13.\n */\n supportsRecording(): boolean;\n /**\n * Whether on-device speech recognition is available.\n *\n * If this method returns false, `start()` will fail and emit an error event with the code `service-not-allowed` or `language-not-supported`.\n */\n isRecognitionAvailable(): boolean;\n\n /**\n * Downloads the offline model for the specified locale.\n * Note: this is only supported on Android 13 and above.\n */\n androidTriggerOfflineModelDownload(options: {\n /** The locale to download the model for, e.g. \"en-US\" */\n locale: string;\n }): Promise<{\n /**\n * On Android 13, \"opened_dialog\" - the model download dialog was shown (fire-and-forget, no events emitted).\n * On Android 14+, \"download_success\" if the model downloaded immediately,\n * or \"download_scheduled\" if the download was queued (e.g., waiting for WiFi).\n */\n status: \"download_success\" | \"opened_dialog\" | \"download_scheduled\";\n message: string;\n }>;\n /**\n * [iOS only] For advanced use cases, you may use this function to set the audio session category and mode.\n *\n * See: https://developer.apple.com/documentation/avfaudio/avaudiosession/1771734-setcategory\n */\n setCategoryIOS(options: SetCategoryOptions): void;\n\n /**\n * [iOS only] Returns the current audio session category and options.\n *\n * See:\n * - [AVAudioSession.Category](https://developer.apple.com/documentation/avfaudio/avaudiosession/category)\n * - [AVAudioSession.CategoryOptions](https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions)\n * - [AVAudioSession.Mode](https://developer.apple.com/documentation/avfaudio/avaudiosession/mode)\n */\n getAudioSessionCategoryAndOptionsIOS(): {\n category: AVAudioSessionCategoryValue;\n categoryOptions: AVAudioSessionCategoryOptionsValue[];\n mode: AVAudioSessionModeValue;\n };\n /**\n * [iOS only] Sets the shared audio session active state.\n *\n * Calls the following on iOS: `AVAudioSession.sharedInstance().setActive(value, options)`\n *\n * See: https://developer.apple.com/documentation/avfaudio/avaudiosession/1616627-setactive\n */\n setAudioSessionActiveIOS(\n value: boolean,\n options?: {\n /** [Default: true] Whether to notify other audio sessions when the active state changes. */\n notifyOthersOnDeactivation: boolean;\n },\n ): void;\n /**\n * Returns the current state of the speech recognizer.\n */\n getStateAsync(): Promise<SpeechRecognitionState>;\n}\n\nexport type SetCategoryOptions = {\n category: AVAudioSessionCategoryValue;\n categoryOptions: AVAudioSessionCategoryOptionsValue[];\n mode?: AVAudioSessionModeValue;\n};\n\ntype SpeechRecognitionState =\n | \"inactive\"\n | \"starting\"\n | \"recognizing\"\n | \"stopping\";\n\n/**\n * [iOS only] See: [AVAudioSession.CategoryOptions](https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions)\n *\n * Use the `AVAudioSessionCategoryOptions` enum to get the correct value.\n */\nexport type AVAudioSessionCategoryOptionsValue =\n (typeof AVAudioSessionCategoryOptions)[keyof typeof AVAudioSessionCategoryOptions];\n\n/**\n * [iOS only] See: [AVAudioSession.Mode](https://developer.apple.com/documentation/avfaudio/avaudiosession/mode)\n *\n * Use the `AVAudioSessionMode` enum to get the correct value.\n */\nexport type AVAudioSessionModeValue =\n (typeof AVAudioSessionMode)[keyof typeof AVAudioSessionMode];\n"]}
|
|
@@ -40,7 +40,26 @@ private func legacyResolveBlock(for promise: Promise) -> EXPromiseResolveBlock {
|
|
|
40
40
|
|
|
41
41
|
public class ExpoSpeechRecognitionModule: Module {
|
|
42
42
|
|
|
43
|
-
var speechRecognizer: ExpoSpeechRecognizer?
|
|
43
|
+
@MainActor var speechRecognizer: ExpoSpeechRecognizer?
|
|
44
|
+
|
|
45
|
+
// The pending `start()` call. `stop()` and `abort()` cancel it so that a start that is still
|
|
46
|
+
// waiting on permissions or recognizer setup can't open the microphone afterwards.
|
|
47
|
+
private let startTaskLock = NSLock()
|
|
48
|
+
private var startTask: Task<Void, Never>?
|
|
49
|
+
|
|
50
|
+
private func cancelStartTask() {
|
|
51
|
+
startTaskLock.withLock {
|
|
52
|
+
startTask?.cancel()
|
|
53
|
+
startTask = nil
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private func runStartTask(_ operation: @escaping @MainActor () async -> Void) {
|
|
58
|
+
startTaskLock.withLock {
|
|
59
|
+
startTask?.cancel()
|
|
60
|
+
startTask = Task { await operation() }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
44
63
|
|
|
45
64
|
// Hack for iOS 18 to detect final results
|
|
46
65
|
// See: https://forums.developer.apple.com/forums/thread/762952 for more info
|
|
@@ -63,7 +82,8 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
63
82
|
|
|
64
83
|
OnDestroy {
|
|
65
84
|
// Cancel any running speech recognizers
|
|
66
|
-
|
|
85
|
+
cancelStartTask()
|
|
86
|
+
Task { @MainActor in
|
|
67
87
|
await speechRecognizer?.abort()
|
|
68
88
|
}
|
|
69
89
|
}
|
|
@@ -170,7 +190,7 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
170
190
|
}
|
|
171
191
|
|
|
172
192
|
AsyncFunction("getStateAsync") { (promise: Promise) in
|
|
173
|
-
Task {
|
|
193
|
+
Task { @MainActor in
|
|
174
194
|
let state = await speechRecognizer?.getState()
|
|
175
195
|
promise.resolve(state ?? "inactive")
|
|
176
196
|
}
|
|
@@ -178,15 +198,17 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
178
198
|
|
|
179
199
|
/** Start recognition with args: lang, interimResults, maxAlternatives */
|
|
180
200
|
Function("start") { (options: SpeechRecognitionOptions) in
|
|
181
|
-
|
|
201
|
+
runStartTask { [self] in
|
|
182
202
|
do {
|
|
183
203
|
let currentLocale = await speechRecognizer?.getLocale()
|
|
204
|
+
guard !Task.isCancelled else { return }
|
|
184
205
|
|
|
185
206
|
// Reset the previous result
|
|
186
207
|
self.previousResult = nil
|
|
187
208
|
|
|
188
209
|
// Re-create the speech recognizer when locales change
|
|
189
|
-
|
|
210
|
+
var recognizer = self.speechRecognizer
|
|
211
|
+
if recognizer == nil || currentLocale != options.lang {
|
|
190
212
|
guard let locale = resolveLocale(localeIdentifier: options.lang) else {
|
|
191
213
|
let availableLocales = SFSpeechRecognizer.supportedLocales().map { $0.identifier }
|
|
192
214
|
.joined(separator: ", ")
|
|
@@ -199,13 +221,16 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
199
221
|
return
|
|
200
222
|
}
|
|
201
223
|
|
|
202
|
-
|
|
224
|
+
recognizer = try await ExpoSpeechRecognizer(
|
|
203
225
|
locale: locale
|
|
204
226
|
)
|
|
227
|
+
guard !Task.isCancelled else { return }
|
|
205
228
|
}
|
|
206
229
|
|
|
207
230
|
if !options.requiresOnDeviceRecognition {
|
|
208
|
-
|
|
231
|
+
let authorized = await SFSpeechRecognizer.hasAuthorizationToRecognize()
|
|
232
|
+
guard !Task.isCancelled else { return }
|
|
233
|
+
guard authorized else {
|
|
209
234
|
sendErrorAndStop(
|
|
210
235
|
error: "not-allowed",
|
|
211
236
|
message: RecognizerError.notAuthorizedToRecognize.message
|
|
@@ -214,7 +239,9 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
214
239
|
}
|
|
215
240
|
}
|
|
216
241
|
|
|
217
|
-
|
|
242
|
+
let hasPermissionToRecord = await AVAudioSession.sharedInstance().hasPermissionToRecord()
|
|
243
|
+
guard !Task.isCancelled else { return }
|
|
244
|
+
guard hasPermissionToRecord else {
|
|
218
245
|
sendErrorAndStop(
|
|
219
246
|
error: "not-allowed",
|
|
220
247
|
message: RecognizerError.notPermittedToRecord.message
|
|
@@ -222,8 +249,17 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
222
249
|
return
|
|
223
250
|
}
|
|
224
251
|
|
|
252
|
+
// End the session of the recognizer that is being replaced (the locale changed)
|
|
253
|
+
if let previous = self.speechRecognizer, previous !== recognizer {
|
|
254
|
+
await previous.reset()
|
|
255
|
+
guard !Task.isCancelled else { return }
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Stored only now, so `stop()` and `abort()` never find a recognizer without handlers
|
|
259
|
+
self.speechRecognizer = recognizer
|
|
260
|
+
|
|
225
261
|
// Start recognition!
|
|
226
|
-
await
|
|
262
|
+
await recognizer?.start(
|
|
227
263
|
options: options,
|
|
228
264
|
resultHandler: { [weak self] result in
|
|
229
265
|
self?.handleRecognitionResult(result, maxAlternatives: options.maxAlternatives)
|
|
@@ -261,6 +297,7 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
261
297
|
}
|
|
262
298
|
)
|
|
263
299
|
} catch {
|
|
300
|
+
guard !Task.isCancelled else { return }
|
|
264
301
|
self.sendEvent(
|
|
265
302
|
"error",
|
|
266
303
|
[
|
|
@@ -364,9 +401,10 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
364
401
|
}
|
|
365
402
|
|
|
366
403
|
Function("stop") { () -> Void in
|
|
367
|
-
|
|
404
|
+
cancelStartTask()
|
|
405
|
+
Task { @MainActor in
|
|
368
406
|
if let recognizer = speechRecognizer {
|
|
369
|
-
|
|
407
|
+
recognizer.stop()
|
|
370
408
|
} else {
|
|
371
409
|
sendEvent("end")
|
|
372
410
|
}
|
|
@@ -374,7 +412,8 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
374
412
|
}
|
|
375
413
|
|
|
376
414
|
Function("abort") { () -> Void in
|
|
377
|
-
|
|
415
|
+
cancelStartTask()
|
|
416
|
+
Task { @MainActor in
|
|
378
417
|
sendEvent("error", ["error": "aborted", "message": "Speech recognition aborted."])
|
|
379
418
|
|
|
380
419
|
if let recognizer = speechRecognizer {
|
|
@@ -47,6 +47,10 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
47
47
|
private var stoppedListening = false
|
|
48
48
|
/// Epoch milliseconds when the audio engine stopped
|
|
49
49
|
private var audioEndTimestampMillis: Double?
|
|
50
|
+
/// Whether "audiostart" was emitted without a matching "audioend" yet
|
|
51
|
+
private var hasEmittedAudioStart = false
|
|
52
|
+
/// Identifies the current recognition task, so that callbacks from a replaced task can be ignored
|
|
53
|
+
private var recognitionGeneration = 0
|
|
50
54
|
|
|
51
55
|
/// Detection timer, for non-continuous speech recognition
|
|
52
56
|
@MainActor var detectionTimer: Timer?
|
|
@@ -137,21 +141,20 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
137
141
|
audioStartHandler: @escaping (String?, Double) -> Void,
|
|
138
142
|
audioEndHandler: @escaping (String?, Double) -> Void,
|
|
139
143
|
volumeChangeHandler: @escaping (Float) -> Void
|
|
140
|
-
) {
|
|
144
|
+
) async {
|
|
141
145
|
self.endHandler = endHandler
|
|
142
146
|
self.audioEndHandler = audioEndHandler
|
|
143
147
|
self.volumeChangeHandler = volumeChangeHandler
|
|
144
148
|
self.errorHandler = errorHandler
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
149
|
+
// Awaited rather than spawned, so the caller's cancellation still applies after the actor hop.
|
|
150
|
+
await startRecognizer(
|
|
151
|
+
options: options,
|
|
152
|
+
resultHandler: resultHandler,
|
|
153
|
+
errorHandler: errorHandler,
|
|
154
|
+
startHandler: startHandler,
|
|
155
|
+
speechStartHandler: speechStartHandler,
|
|
156
|
+
audioStartHandler: audioStartHandler
|
|
157
|
+
)
|
|
155
158
|
}
|
|
156
159
|
|
|
157
160
|
/// Stops the speech recognizer.
|
|
@@ -173,10 +176,8 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
173
176
|
/// Cancels the current speech recognition task.
|
|
174
177
|
/// This is different from `stop` in that the recognition task is immediately cancelled and no
|
|
175
178
|
/// final result is emitted.
|
|
176
|
-
@MainActor func abort() {
|
|
177
|
-
|
|
178
|
-
await reset(andEmitEnd: true)
|
|
179
|
-
}
|
|
179
|
+
@MainActor func abort() async {
|
|
180
|
+
await reset(andEmitEnd: true)
|
|
180
181
|
}
|
|
181
182
|
|
|
182
183
|
///
|
|
@@ -210,6 +211,7 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
210
211
|
speechStartHandler: @escaping () -> Void,
|
|
211
212
|
audioStartHandler: @escaping (String?, Double) -> Void
|
|
212
213
|
) {
|
|
214
|
+
guard !Task.isCancelled else { return }
|
|
213
215
|
// Reset the speech recognizer before starting
|
|
214
216
|
reset(andEmitEnd: false)
|
|
215
217
|
|
|
@@ -244,6 +246,7 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
244
246
|
} else {
|
|
245
247
|
try prepareMicrophoneRecognition(request: request, options: options)
|
|
246
248
|
}
|
|
249
|
+
try Task.checkCancellation()
|
|
247
250
|
let audioStartTimestampMillis = Date().timeIntervalSince1970 * 1000
|
|
248
251
|
|
|
249
252
|
startRecognitionTask(
|
|
@@ -256,11 +259,20 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
256
259
|
isSourcedFromFile: isSourcedFromFile
|
|
257
260
|
)
|
|
258
261
|
|
|
259
|
-
|
|
260
|
-
|
|
262
|
+
hasEmittedAudioStart = true
|
|
263
|
+
let outputFilePath = outputFileUrl?.absoluteString
|
|
264
|
+
// Emitted from the main actor, like "end", so that on a restart
|
|
265
|
+
// the previous session's "end" can't arrive after this "start"
|
|
266
|
+
Task { @MainActor in
|
|
267
|
+
// Emit the "start" event to indicate that speech recognition has started
|
|
268
|
+
startHandler()
|
|
261
269
|
|
|
262
|
-
|
|
263
|
-
|
|
270
|
+
// If user has opted in to recording, emit an "audiostart" event with the path
|
|
271
|
+
audioStartHandler(outputFilePath, audioStartTimestampMillis)
|
|
272
|
+
}
|
|
273
|
+
} catch is CancellationError {
|
|
274
|
+
// `stop()` or `abort()` cancelled this start during setup. They emit the "end" event.
|
|
275
|
+
reset(andEmitEnd: false)
|
|
264
276
|
} catch {
|
|
265
277
|
errorHandler(error)
|
|
266
278
|
reset(andEmitEnd: true)
|
|
@@ -278,11 +290,14 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
278
290
|
) {
|
|
279
291
|
let audioEngine = self.audioEngine
|
|
280
292
|
let shouldRunTimers = !continuous && !isSourcedFromFile
|
|
293
|
+
recognitionGeneration += 1
|
|
294
|
+
let generation = recognitionGeneration
|
|
281
295
|
|
|
282
296
|
self.task = recognizer.recognitionTask(
|
|
283
297
|
with: request,
|
|
284
298
|
resultHandler: { [weak self] result, error in
|
|
285
299
|
self?.recognitionHandler(
|
|
300
|
+
generation: generation,
|
|
286
301
|
audioEngine: audioEngine,
|
|
287
302
|
result: result,
|
|
288
303
|
error: error,
|
|
@@ -348,6 +363,8 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
348
363
|
options: SpeechRecognitionOptions
|
|
349
364
|
) throws {
|
|
350
365
|
try Self.setupAudioSession(options.iosCategory)
|
|
366
|
+
// Setting up the audio session is slow. Don't open the microphone if the start was cancelled meanwhile.
|
|
367
|
+
try Task.checkCancellation()
|
|
351
368
|
registerAudioSessionObservers()
|
|
352
369
|
self.audioEngine = AVAudioEngine()
|
|
353
370
|
|
|
@@ -500,12 +517,15 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
500
517
|
let filePath = self.outputFileUrl?.absoluteString
|
|
501
518
|
let timestamp = audioEndTimestampMillis ?? Date().timeIntervalSince1970 * 1000
|
|
502
519
|
outputFileUrl = nil
|
|
503
|
-
|
|
504
|
-
|
|
520
|
+
let shouldEmitAudioEnd = hasEmittedAudioStart
|
|
521
|
+
hasEmittedAudioStart = false
|
|
522
|
+
// Not a plain `Task {}`: that would first wait for this actor, which a restart keeps busy,
|
|
523
|
+
// and deliver the "end" of the previous session after the "start" of the new one
|
|
524
|
+
Task { @MainActor in
|
|
525
|
+
if shouldEmitAudioEnd {
|
|
505
526
|
self.audioEndHandler?(filePath, timestamp)
|
|
506
|
-
self.audioEndHandler = nil
|
|
507
|
-
self.endHandler?()
|
|
508
527
|
}
|
|
528
|
+
self.endHandler?()
|
|
509
529
|
}
|
|
510
530
|
}
|
|
511
531
|
|
|
@@ -533,7 +553,7 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
533
553
|
}
|
|
534
554
|
|
|
535
555
|
/// Reset the speech recognizer.
|
|
536
|
-
|
|
556
|
+
func reset(andEmitEnd: Bool = false) {
|
|
537
557
|
let taskWasRunning = task != nil
|
|
538
558
|
let shouldEmitEndEvent = andEmitEnd || taskWasRunning || stoppedListening
|
|
539
559
|
|
|
@@ -575,9 +595,6 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
575
595
|
// (e.g. in the case of a setup error)
|
|
576
596
|
print("SpeechRecognizer: end")
|
|
577
597
|
if shouldEmitEndEvent {
|
|
578
|
-
Task { @MainActor in
|
|
579
|
-
self.errorHandler = nil
|
|
580
|
-
}
|
|
581
598
|
end()
|
|
582
599
|
}
|
|
583
600
|
audioEndTimestampMillis = nil
|
|
@@ -746,12 +763,8 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
746
763
|
Task { [weak self] in
|
|
747
764
|
let typeValue = notification.userInfo?[AVAudioSessionInterruptionTypeKey] as? UInt
|
|
748
765
|
let type = typeValue.flatMap(AVAudioSession.InterruptionType.init(rawValue:))
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
// Emit "interrupted" error event
|
|
752
|
-
await self?.emitError(.audioSessionInterrupted)
|
|
753
|
-
// Force-stop the recognition task and emit the "end" event
|
|
754
|
-
await self?.reset(andEmitEnd: true)
|
|
766
|
+
if type == .began {
|
|
767
|
+
await self?.handleAudioInterruptionBegan()
|
|
755
768
|
}
|
|
756
769
|
}
|
|
757
770
|
}
|
|
@@ -763,17 +776,27 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
763
776
|
) { [weak self] _ in
|
|
764
777
|
let appState = UIApplication.shared.applicationState
|
|
765
778
|
Task { [weak self] in
|
|
766
|
-
|
|
767
|
-
await self?.handleAudioRouteChange(taskState: taskState, appState: appState)
|
|
779
|
+
await self?.handleAudioRouteChange(appState: appState)
|
|
768
780
|
}
|
|
769
781
|
}
|
|
770
782
|
|
|
771
783
|
}
|
|
772
784
|
|
|
773
|
-
private func
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
785
|
+
private func handleAudioInterruptionBegan() {
|
|
786
|
+
// Read the task state here, on the actor, so it can't go stale before we act on it
|
|
787
|
+
let taskState = task?.state
|
|
788
|
+
guard taskState == .running || taskState == .starting else {
|
|
789
|
+
return
|
|
790
|
+
}
|
|
791
|
+
// Emit "interrupted" error event
|
|
792
|
+
emitError(.audioSessionInterrupted)
|
|
793
|
+
// Force-stop the recognition task and emit the "end" event
|
|
794
|
+
reset(andEmitEnd: true)
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
private func handleAudioRouteChange(appState: UIApplication.State) {
|
|
798
|
+
// Read the task state here, on the actor, so it can't go stale before we act on it
|
|
799
|
+
let taskState = task?.state
|
|
777
800
|
// We only care about route changes when the recognizer is active
|
|
778
801
|
if taskState == .running || taskState == .starting {
|
|
779
802
|
// App deactivation can emit a route change while the audio session is
|
|
@@ -927,7 +950,20 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
927
950
|
ExtAudioFileWrite(audioFileRef, convertedBuffer.frameLength, convertedBuffer.audioBufferList)
|
|
928
951
|
}
|
|
929
952
|
|
|
953
|
+
/// The recognition task for `generation`, or nil once it has ended or been replaced by a newer one
|
|
954
|
+
private func task(forGeneration generation: Int) -> SFSpeechRecognitionTask? {
|
|
955
|
+
return generation == recognitionGeneration ? task : nil
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
private func reset(ifGeneration generation: Int) {
|
|
959
|
+
guard generation == recognitionGeneration else {
|
|
960
|
+
return
|
|
961
|
+
}
|
|
962
|
+
reset()
|
|
963
|
+
}
|
|
964
|
+
|
|
930
965
|
nonisolated private func recognitionHandler(
|
|
966
|
+
generation: Int,
|
|
931
967
|
audioEngine: AVAudioEngine?,
|
|
932
968
|
result: SFSpeechRecognitionResult?,
|
|
933
969
|
error: Error?,
|
|
@@ -954,7 +990,7 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
954
990
|
|
|
955
991
|
if let result: SFSpeechRecognitionResult, shouldEmitResult {
|
|
956
992
|
Task { @MainActor in
|
|
957
|
-
let taskState = await task?.state
|
|
993
|
+
let taskState = await task(forGeneration: generation)?.state
|
|
958
994
|
// Make sure the task is running before emitting the result
|
|
959
995
|
if taskState != .none {
|
|
960
996
|
resultHandler(result)
|
|
@@ -965,7 +1001,7 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
965
1001
|
if let error: Error {
|
|
966
1002
|
// TODO: don't emit no-speech if there were already interim results
|
|
967
1003
|
Task { @MainActor in
|
|
968
|
-
if await task != nil {
|
|
1004
|
+
if await task(forGeneration: generation) != nil {
|
|
969
1005
|
// Don't emit any errors after the task has finished
|
|
970
1006
|
errorHandler(error)
|
|
971
1007
|
}
|
|
@@ -976,7 +1012,7 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
976
1012
|
|| receivedFinalResult
|
|
977
1013
|
{
|
|
978
1014
|
Task { @MainActor in
|
|
979
|
-
await reset()
|
|
1015
|
+
await reset(ifGeneration: generation)
|
|
980
1016
|
}
|
|
981
1017
|
return
|
|
982
1018
|
}
|
package/package.json
CHANGED
|
@@ -247,6 +247,26 @@ export type ExpoSpeechRecognitionOptions = {
|
|
|
247
247
|
* e.g. "com.google.android.as" or "com.samsung.android.bixby.agent"
|
|
248
248
|
*/
|
|
249
249
|
androidRecognitionServicePackage?: string;
|
|
250
|
+
/**
|
|
251
|
+
* [Android only] Request audio focus while recognizing from the microphone.
|
|
252
|
+
*
|
|
253
|
+
* Other apps (e.g. music or podcast players) pause their playback when recognition starts,
|
|
254
|
+
* and resume it when recognition ends.
|
|
255
|
+
*
|
|
256
|
+
* This requests [`AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE`](https://developer.android.com/reference/android/media/AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE),
|
|
257
|
+
* the focus type Android recommends for speech recognition. It has no effect when `audioSource` is set.
|
|
258
|
+
*
|
|
259
|
+
* This is mainly useful with `continuous` or `recordingOptions.persist`. Without those,
|
|
260
|
+
* some recognition services (e.g. Google's) already request audio focus themselves.
|
|
261
|
+
*
|
|
262
|
+
* The focus is held for the duration of a session, so if you call `start()` again from the "end" event,
|
|
263
|
+
* other apps may briefly resume their playback between sessions.
|
|
264
|
+
*
|
|
265
|
+
* On iOS, use `iosCategory` to control how other apps' audio is handled.
|
|
266
|
+
*
|
|
267
|
+
* Default: false
|
|
268
|
+
*/
|
|
269
|
+
androidAudioFocus?: boolean;
|
|
250
270
|
/**
|
|
251
271
|
* Extra options to provide to the Android Recognition intent.
|
|
252
272
|
*
|