AudioRecord:start()状态-38 [英] AudioRecord: start() status -38

查看:756
本文介绍了AudioRecord:start()状态-38的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题: 我使用SpeechRecognizer识别几个单词. 我用

I have the following problem: I use SpeechRecognizer to identify a few words. I use the

public void onResults

销毁SpeechRecognizer的方法.

method to destroy the SpeechRecognizer.

在销毁之后,我立即初始化一个AudioRecord并从麦克风开始录音. 这会在我的logcat中导致以下错误:

Right after the destruction I initialize an AudioRecord and start recording from the mic. This leads to the following error in my logcat:

12-09 00:44:01.976: E/AudioRecord(21185): start() status -38

我的代码中没有抛出异常. AudioRecord只是无法正常启动. 我假设SpeechRecognizer不能足够快地释放麦克风, 因为如果我在AudioRecord的初始化之前添加Thread.sleep(200), 没有遇到这个问题.

No exception is thrown in my code. The AudioRecord just does not start properly. I am assuming that the SpeechRecognizer does not release the microphone quickly enough, because if I add a Thread.sleep(200) in front of the initialization of the AudioRecord, I do not experience this issue.

由于明显的原因,此解决方案非常糟糕.因此,我有以下问题:

This solution is very bad for obvious reasons. Thus, I have the following question:

如何检查AudioRecord是否正确初始化? (我的代码中没有异常.)

How do I check whether the AudioRecord is initialized properly? (I do not get an exception in my code.)

_audioRecord.getState() == AudioRecord.STATE_UNINITIALIZED

也是错误的.

或者如何检查SpeechRecognizer是否正确释放了麦克风?

Or how do I check whether SpeechRecognizer released the microphone properly?

非常感谢!

推荐答案

您需要确保以onPause()或类似方法发布audioRecord.stop();audioRecord.release();.如果不这样做,则下次运行该应用程序时,您将无法访问该设备,并且会得到start() status -38

You need to make sure you issue audioRecord.stop(); and audioRecord.release(); in your onPause() or similar methods. If you don't, the next time you run the app, you won't get access to the device, and you'll get start() status -38

这篇关于AudioRecord:start()状态-38的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆