Reputation: 81
I have a personal Android app that performs speech-to-text that I have been using for years on my Android phones. Recently, I updated my Pixel 3 to Android 12 (S) and the calls to SpeechRecognizer have stopped working.
I'm invoking it in a pretty standard way:
SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(MainActivity.this);
sr.setRecognitionListener(listener);
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.RECORD_AUDIO}, 1);
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
sr.startListening(intent);
Since upgrading to Android 12, after the call to startListening()
, the onError()
listener callback is called immediately with an error code of ERROR_CLIENT
. The phone also makes a quick sort of "beep-boop" failure sound, though it indicates that it is using the microphone.
The logcat output (below) has some errors and I find it interesting that it indicates that "prefer offline" is enabled though I don't have that in the Intent.
Any thoughts? Is this a Pixel 3 issue?
021-11-03 10:11:16.471 24887-24887/? I/AiAi: AiAiSpeechRecognitionService#onStartListening
2021-11-03 10:11:16.474 24887-24887/? I/RecognitionServiceImpl: RecognitionService#onStartListening
2021-11-03 10:11:16.474 1071-4475/? D/audio_hw_primary: out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
2021-11-03 10:11:16.474 24887-24887/? I/IntentParsingUtil: Using Locale.getDefault() for recognition: null
2021-11-03 10:11:16.474 24887-24887/? I/AiAiSpeechRecognition: [AiAi RecognitionService] session start logged
2021-11-03 10:11:16.474 24887-24887/? I/IntentParsingUtil: Using Locale.getDefault() for recognition: null
2021-11-03 10:11:16.474 24887-24887/? I/IntentParsingUtil: Using Locale.getDefault() for recognition: null
2021-11-03 10:11:16.474 24887-24887/? I/AiAiSpeechRecognition: [AiAi RecognitionService] prefer offline logged
2021-11-03 10:11:16.475 24887-24887/? I/SodaSpeechRecognizer: Offline recognizer - start listening
2021-11-03 10:11:16.475 24887-24922/? I/AiAiAudio: #startListening
... Some audio stuff here ...
2021-11-03 10:11:16.576 24887-4930/? I/AiAiAudio: run(): Tee read loop starting
2021-11-03 10:11:16.578 24887-24923/? E/native: E1103 10:11:16.578536 24923 language_pack_utils.cc:346] No usable config found in LP at: /data/user/0/com.google.android.as/files/superpacks/speech-recognition/aiai_en_us_v27
2021-11-03 10:11:16.578 24887-24923/? E/native: E1103 10:11:16.578691 24923 soda_impl.cc:522] Terse enabled but could not initialize processor: Terse Processor: No usable config found in LP.
2021-11-03 10:11:16.579 24887-24923/? I/SodaDetectionHandler: Initialized SODA with status: 5
2021-11-03 10:11:16.580 24887-24923/? E/SodaSpeechRecognizer: Soda recognizer failed to initialize: ConfigStatus 5!
2021-11-03 10:11:16.580 24887-24923/? W/RecognitionClient: #onError space agsa_transcription_SODA_INITIALIZATION_ERROR code 5!
2021-11-03 10:11:16.580 24887-24923/? I/AiAiSpeechRecognition: [AiAi RecognitionService] mic close logged
2021-11-03 10:11:16.580 24887-24923/? I/AiAiAudio: #stopListeningAndCleanUpSession
2021-11-03 10:11:16.580 24887-24923/? I/AiAiAudio: stop(): Stopping AudioTee
2021-11-03 10:11:16.582 14403-14403/com.example.tester_ii_s I/FU: onError: 5
2021-11-03 10:11:16.582 24887-24922/? I/AiAiSpeechRecognition: [AiAi RecognitionService] session end logged
Upvotes: 8
Views: 4195
Reputation: 96
I have faced the same issue on my Pixel 6 Pro with API 33 (Android 13). For some reasons AiAiSpeechRecognition is returned as a default SpeechRecognition service. Unfortunately, it doesn't look that it's some how close to production solution that can be used as a SpeechRecognition service for third party apps. en-US is not recognized, es-ES language pack can't be downloaded...
I can only suggest to avoid using AiAiSpeechRecognition by hard coding still available "com.google.android.apps.speech.tts.googletts.service.GoogleTTSRecognitionService" it was suggested by Woalk above.
Another option is to use the following line of code, but it is also some kind of hard code, because the string constant can be changed in future. For now it works on API 33 and returns system default speech recognition service. For now it is "com.google.android.apps.speech.tts.googletts.service.GoogleTTSRecognitionService", but it can be change in future:
String serviceComponent = Settings.Secure.getString(getContext().getContentResolver(), "voice_recognition_service");
Upvotes: 2
Reputation: 1
I was initially getting an error of "Language pack not installed", coming from the previously mentioned AiAiSpeechRecognition service, something previously I hadn't seen from my app.
For context my app is a language learning app and the user is trying to learn a language which is not the Locale.default. When I checked the Settings > Apps > Default apps > Digital assistant app > Voice input and changing it was set to Android System Intelligence, with no option for Speech Services by Google. Oddly when searching for this "Speech Services by Google" in the Play Store I could find it and it was up to date as of October. I tried the suggestion of explicitly outlining the SpeechRecognition to use "com.google.android.tts" but it failed to bind to it, which suggests the service isn't running.
I then uninstalled Speech Services by Google and reinstalled, then revisited Settings > Apps > Default apps > Digital assistant app > Voice input and changing and I could now select Speech services. Which has fixed the issue in my app, however the option for Android System Intelligence is now gone from the choices available since choosing Speech Services.
This is certainly a bug in the OS and there doesn't seem to be a programmatic way of fixing it.
Upvotes: 0
Reputation: 156
This problem seems to come from the underlying SpeechRecognizer engine of the respective device, in this case, AiAiSpeechRecognition.
AiAiSpeechRecognition is part of the Android System Intelligence package that is new for Android 12 for features like LiveCaption etc. However, it seems to be incompatible (for now) with the SpeechRecognizer API.
For some reason, upgrading devices to Android 12 has a good chance of the default SpeechRecognizer app being set to Android System Intelligence anyway, even though it isn't supposed to.
This can be fixed by the user of the device, by going into Settings > Apps > Default apps > Digital assistant app > Voice input and changing it back to "Speech services by Google" (you may first need to update Speech services by Google via the Play Store). Once this is done, Android System Intelligence will disappear from the list of options in that setting, suggesting it was never intended to be chosen in the first place.
You can also solve it programmatically for your app only. For that, you need to specifically request Speech services by Google as your SpeechRecognizer service:
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(
mContext,
new ComponentName(
"com.google.android.tts",
"com.google.android.apps.speech.tts.googletts.service.GoogleTTSRecognitionService"
)
);
Note though that by doing this,
This should therefore be used as a temporary workaround only.
From all I can gather, the fact that Android System Intelligence is chosen as SpeechRecognizer engine is a bug in Android 12 and should be fixed by Google. I have not yet searched Google's issue tracker for this, maybe it should be submitted there.
Upvotes: 4