问题描述
我一直有这个问题,初始化 AudioRecord
为Android。我搜索的网站,但没有成功在相当长一段时间。
I've been having this issue with initializing AudioRecord
for Android. I searched for quite a while on the web with no success.
有关手机,我用的是三星的GalaxyS上的SDK版本7.对于 AudioRecord
初始化,我使用8000的采样率,单声道通道配置,16位用于音频的格式,并根据日志,所述minBufferSize被设定为4160。我已经添加了AUDIO_RECORD权限清单。
For the phone, I'm using a Samsung GalaxyS on SDK version 7. For the AudioRecord
initialization, I'm using 8000 as the sample rate, MONO for channel config, 16bit for audio format, and according to the log, the minBufferSize is set to be 4160. I have added the AUDIO_RECORD permission to the manifest.
我的code的初始化如下:
My code for the initialization is as follows:
...
private static int SAMPLE_RATE = 8000;
private static int CHANNEL_CONFIG = AudioFormat.CHANNEL_CONFIGURATION_MONO;
private static int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
// ??? Both 8Bit and Default are deemed illegal.
public MicVolumeManager() {
this.bufferSize = AudioRecord.getMinBufferSize(SAMPLE_RATE,
CHANNEL_CONFIG, AUDIO_FORMAT);
PhoneDebugger.debug("AUDIO-BUFFER-SIZE",
Integer.toString(this.bufferSize));
this.recorder = new AudioRecord(AudioSource.MIC, SAMPLE_RATE,
CHANNEL_CONFIG, AUDIO_FORMAT, this.bufferSize);
this.audioBuffer = new byte[this.bufferSize];
}
...
然而,对象(this.recorder)未能被初始化。以下是使用DDMS日志:
However, the object (this.recorder) failed to be initialized. The following is from the log using DDMS:
AUDIO-BUFFER-SIZE(3253): 4160
AudioRecord(3253):设置():采样率8000,通道16,frameCount 2080
AudioPolicyManager(2175): getInput()的InputSource 1,samplingRate 8000,格式1,通道10,声学0
AudioFlinger(2175): openInput()openInputStream返回的输入为0x0,SamplingRate 8000,格式1,通道10,音响0,状态-17
AudioRecord(3253):无法获取音频输入记录源1
AudioRecord-JNI(3253):错误创建AudioRecord实例:初始化检查失败
AudioRecord Java的(3253): [android.media.AudioRecord]错误code -20初始化本地AudioRecord对象时。
任何帮助吗?非常感谢!
Any help please? Many thanks!
推荐答案
在我看来,原因是没有传唤AudioRecord.release()用于AudioRecord的previous实例;它捆绑本土资源AudioFlinger和干扰后续AudioRecord实例。看到它在三星的Fascinate(银河S)的Android 2.1(埃克莱尔);无论是Eclair的还是三星的实施可能会特别不耐症。
For me, the cause was failure to call AudioRecord.release() for a previous instance of AudioRecord; it tied up native resources in AudioFlinger and interfered with subsequent AudioRecord instances. Saw it on a Samsung Fascinate (Galaxy S) Android 2.1 (Eclair); either the Eclair or the Samsung implementation may be particularly intolerant.
这篇关于< AudioRecord> "无法获取音频输入记录源1"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!