Consider this Kotlin code to init a Google speech recognizer:
recognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
.apply {
putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
)
putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US")
putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3)
putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true)
}
This used to work up until SDK 32 but is failing since. The crux of the problem is the last put extra, EXTRA_PREFER_OFFLINE. If you don't include it, the recognizer is set up, but not always.
Apparently some OEMs include online recognitions and others don't, whereas others (inc. Pixel) enable users to control online/offline in their preferences.
Does anyone know of a way to detect the status of the device, and accordingly add this put extra for devices with SDK > 32?
Thanks!