为什么 SpeechRecognizer 突然停止工作?

Why has SpeechRecognizer suddenly stopped working?

我的 Android 应用程序 (Xamarin) 使用语音识别。这在 Android 8、11 和 12 的智能手机上运行良好。自几周以来,我的应用程序的语音识别已停止与 Android 11(测试了 2 种不同的智能手机)一起工作。 它在 Android 8 + 12 下仍然可以正常工作! Gboard 语音识别仍然适用于 Android 11。 我的智能手机 Android 11 没有更新,我的应用程序也没有更新。

OnResults 总是从 SpeechRecognizer 调用之前识别的文本。现在,OnResults 使用空 Bundle 调用。 OnErrorSpeechRecognizerError.NoMatch 调用。

如果我使用 Intent 进行语音识别,它就可以工作!如果我使用具有相同参数的 SpeechRecognizer,它就不起作用。我必须使用 SpeechRecognizer,因为我不想在我的应用程序中使用 Android 对话框。

那么使用 SpeechRecognizer 有什么不同?

Logcat:

With Intent only

04-29 12:25:07.004 24526 24672 I A       : TTL (0 seconds) reached - destroy SODA
04-29 12:25:07.007   961   961 D sound_trigger_platform: platform_stdev_check_and_update_concurrency: concurrency active 0, tx 0, rx 0, concurrency session_allowed 1
04-29 12:25:07.009 24526 24667 I A       : Received a final result for a segment
04-29 12:25:07.009 24526 24667 I A       : Received the final result for the recognition
04-29 12:25:07.010 24526 24690 I A       : updated TranscriptionState: TranscriptionState{language=Deutsch (Deutschland), liveTranscription=# com.google.android.apps.search.transcription.f.ay@72c8abf5, finalRecognitionResults=# com.google.android.apps.search.transcription.f.o@c09c735a, hasStartOfSpeech=true, isMicOpen=true, appflowErrorStatus=null, speechLevel=0, audioUri=, lastAudioRationaleToastTimestampLoaded=false} for request-id 1191836547
04-29 12:25:07.010  1477  2981 I system_server: oneway function results will be dropped but finished with status OK and parcel size 4
04-29 12:25:07.010 24526 24526 I A       : #setLatestRecognizedText stableText: Hallo, pendingText: 
04-29 12:25:07.010  1477 27263 I SoundTriggerMiddlewareLogging: setCaptureState[this=com.android.server.soundtrigger_middleware.SoundTriggerMiddlewareImpl@51cdb90, caller=1041/1059](false)
04-29 12:25:07.010 24526 24690 I A       : Offline recognizer - stop detection
04-29 12:25:07.014  1477  2981 I system_server: oneway function results will be dropped but finished with status OK and parcel size 4
04-29 12:25:07.014  1477  2981 I chatty  : uid=1000(system) Binder:1477_14 identical 1 line
04-29 12:25:07.015  1477  2981 I system_server: oneway function results will be dropped but finished with status OK and parcel size 4
04-29 12:25:07.015 24629 24680 I A       : AudioRequestListeningSession stop listening status: CLOSED

With SpeechRecognizer

04-29 12:28:07.216 24526 24690 I A       : TTL (0 seconds) reached - destroy SODA
04-29 12:28:07.224  1477  2951 I system_server: oneway function results will be dropped but finished with status OK and parcel size 4
04-29 12:28:07.246   961 17127 D audio_hw_primary: disable_audio_route: usecase(10) reset and update mixer path: audio-record
04-29 12:28:07.247   961 17127 I soundtrigger: audio_extn_sound_trigger_update_stream_status: send event 12: usecase id 10, type 1
04-29 12:28:07.247   961 17127 D sound_trigger_platform: platform_stdev_check_and_update_concurrency: concurrency active 0, tx 1, rx 0, concurrency session_allowed 1
04-29 12:28:07.247   961 17127 D sound_trigger_platform: platform_stdev_check_concurrency_supported: capture concurrency  allowed, usecase type 1 voice_concur 0 voip_concur 0
04-29 12:28:07.247   961 17127 D audio_hw_primary: disable_snd_device: snd_device(84: voice-rec-mic)
04-29 12:28:07.251   961 17127 D sound_trigger_platform: platform_stdev_check_and_update_concurrency: concurrency active 0, tx 0, rx 0, concurrency session_allowed 1
04-29 12:28:07.254  1477  2951 I system_server: oneway function results will be dropped but finished with status OK and parcel size 4
04-29 12:28:07.254  1477  5904 I SoundTriggerMiddlewareLogging: setCaptureState[this=com.android.server.soundtrigger_middleware.SoundTriggerMiddlewareImpl@51cdb90, caller=1041/1059](false)
04-29 12:28:07.260  1477  5904 I SoundTriggerMiddlewareLogging: setCaptureState[this=com.android.server.soundtrigger_middleware.SoundTriggerMiddlewareImpl@51cdb90, caller=1041/1059](false)
04-29 12:28:07.261  1477  8707 I system_server: oneway function results will be dropped but finished with status OK and parcel size 4
04-29 12:28:07.261 24629 24679 I A       : AudioRequestListeningSession stop listening status: CLOSED

AndroidManifest.xml的一些细节:

android:versionCode="30"
android:targetSdkVersion="30" 
android:minSdkVersion="22"

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<queries>
    <intent>
        <action android:name="android.speech.RecognitionService" />
    </intent>
</queries>

非常感谢,祝你有愉快的一天,

尝试从您的意图中删除以下一项或全部内容:

RecognizerIntent.EXTRA_MAX_RESULTS RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS

在我的例子中,我必须删除所有的,否则它不会工作

此错误是 Google 应用更新 13.16.8.23.arm64 和一些 Intent 参数使用的组合。

如果设置了以下参数

RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS
RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS 
RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS

已安装最新的 Google 应用程序,SpeechRecognizer 将无法工作。

如果卸载了最新的 Google 应用程序(这将回滚到旧版本),SpeechRecognizer 将再次工作,即使使用此参数也是如此。

如果从代码中删除参数,SpeechRecognizer 工作正常,即使使用最新的 Google 应用程序也是如此。