Android SpeechRecognizer Audio Recording Error

风格不统一 提交于 2020-04-11 04:43:26

问题


I'm trying to use SpeechRecognizer on Android without Intent Dialog. It works fine on most of devices but some devices return Audio Recording Error (Error Code 3) and There's no detail for this error. Is there any solution or reason for this?

Thank you!!


回答1:


I had the same error when Google App(com.google.android.googlequicksearchbox) does not have recording permission.

In addition, SpeechRecognizer uses service of com.google.android.googlequicksearchbox. Thus, if this app is disabled or uninstalled, SpeechRecognizer may not work.




回答2:


You should go to system setting, Apps, Google app, then enable its permission of microphone. That's exactly the cause of ERROR_AUDIO(Error Code 3).




回答3:


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

Set this in your manifest. if still not working, then state which device is causing error.




回答4:


Error Code 6 means Error Speech Timeout, while Audio Recording Error has value 3 (see here: https://developer.android.com/reference/android/speech/SpeechRecognizer.html). Assuming that you have Error Speech Timeout, you can do the following:

public void OnError(SpeechRecognizerError error) {
String errorMessage = error.ToString();
    if (errorMessage.Contains ("SpeechTimeout"))
                {   this.OnDestroy();
                    this.OnCreate();
                }
}

This will allow you to restart your SpeechRecognizer.

On the other hand, if you are having difficulties with Audio Recording Error, I'd be glad to find the solution, since I'm facing the same problem.



来源:https://stackoverflow.com/questions/46376193/android-speechrecognizer-audio-recording-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!