我正在尝试制作一个应用程序,该应用程序在打开时会倾听用户的声音并提供他们当前所说内容的记录。我一直在尝试找到一种方法来克服 Android 手机在用户暂停后立即停止收听的方式,并且我找到了一个能够克服它的存储库。
当我下载并运行他们的仓库时,它在我的 Android 10 Google Pixel 3 设备上运行良好,但是当我将他们的代码粘贴到我的仓库中时(并注释掉进度条,因为我的布局中没有进度条),应用程序将无法打开,我收到此错误:
Connected to process 14522 on device 'google-pixel_3-89SX0FLJP'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
W/ample.wordsmit: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/ample.wordsmit: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
I/VoiceRecognitionActivity: isRecognitionAvailable: false
E/SpeechRecognizer: bind to recognition service failed
E/ActivityThread: Activity com.example.wordsmith.MainActivity has leaked
ServiceConnection android.speech.SpeechRecognizer$Connection@f9bf192 that was originally bound here
android.app.ServiceConnectionLeaked: Activity com.example.wordsmith.MainActivity has leaked ServiceConnection android.speech.SpeechRecognizer$Connection@f9bf192 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1835)
at android.app.LoadedApk.getServiceDispatcherCommon(LoadedApk.java:1707)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1686)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1819)
at android.app.ContextImpl.bindService(ContextImpl.java:1749)
at android.content.ContextWrapper.bindService(ContextWrapper.java:756)
at android.speech.SpeechRecognizer.startListening(SpeechRecognizer.java:286)
at com.example.wordsmith.MainActivity.onCreate(MainActivity.java:83)
at android.app.Activity.performCreate(Activity.java:7994)
at android.app.Activity.performCreate(Activity.java:7978)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3404)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7664)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
与我在同一设备上运行其他 repo 时的日志相比:
W/.googleapivoic: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/.googleapivoic: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
I/VoiceRecognitionActivity: isRecognitionAvailable: true
I/VoiceRecognitionActivity: resume
I/VoiceRecognitionActivity: isRecognitionAvailable: true
I/VoiceRecognitionActivity: pause
I/VoiceRecognitionActivity: stop
I/VoiceRecognitionActivity: resume
I/VoiceRecognitionActivity: isRecognitionAvailable: true
我很确定它会因为 else 子句中的 finish() 而关闭:
private void resetSpeechRecognizer() {
if(speech != null)
speech.destroy();
speech = SpeechRecognizer.createSpeechRecognizer(this);
Log.i(LOG_TAG, "isRecognitionAvailable: " + SpeechRecognizer.isRecognitionAvailable(this));
if(SpeechRecognizer.isRecognitionAvailable(this))
speech.setRecognitionListener(this);
else
finish();
}
我不明白为什么语音识别在我的存储库中失败,但在代码几乎完全相同且我们的清单文件也相同时,在他们的存储库中却没有。
(我应该注意,我不认为我删除进度条是问题,因为当我在他们的仓库中注释掉它时,它仍然运行良好)
我们的构建配置相差一行(它们有 public static final String FLAVOR = "";),但添加它并不能解决它。我是否缺少语音识别所需的其他一些组件?
这是我在这里提出的第一个问题,所以如果我可以提供有关我的问题的更多信息,请告诉我。感谢您花时间阅读本文,我将不胜感激任何建议或帮助,因为我很好并且真的被卡住了:)