开发者

"Could not get audio input for record source 1" when trying to initialize AudioRecord

开发者 https://www.devze.com 2023-02-09 16:12 出处:网络
I keep getting this error when trying to initialize and AudioRecord object, in an attempt to record sounds using the emulator using Eclipse.

I keep getting this error when trying to initialize and AudioRecord object, in an attempt to record sounds using the emulator using Eclipse.

I have tried with various bit sampling rates, 8000 is the only one that is valid, but the error continues to appear. I have tried on various versions of the sdk, 1.5, 1.6, 2, 2.2 and 2.3.1. (and combinations of开发者_如何学C with the AVD).

Here is the code:

       Log.v(TAG, "About to initialize recording");
   //int[] samplingRates = {44100, 22050, 16000, 11025, 8000};
   int[] samplingRates = {8000};

    for (int i = 0; i < samplingRates.length; ++i)
    {
        try
        {
            Log.d(TAG,"Trying sampling rate: " + samplingRates[i]);
            int min = AudioRecord.getMinBufferSize(samplingRates[i], 
                    AudioFormat.CHANNEL_CONFIGURATION_MONO,
                    //AudioFormat.CHANNEL_IN_MONO,
                    AudioFormat.ENCODING_PCM_16BIT);
            Log.d(TAG,"MinBufferSize: " + min);

            AudioRecord record = new AudioRecord(MediaRecorder.AudioSource.MIC, samplingRates[i],
                    AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, min);
            if (record.getState() == AudioRecord.STATE_INITIALIZED)
            {
                Log.d("Recorder", "Audio recorder initialised at " + record.getSampleRate());
                return record;
            }
            record.release();
            record = null;
        }
        catch (IllegalArgumentException e)
        {
            // Try the next one.
            Log.d(TAG,"Initialization failed");
        }
    }
    // None worked.
    return null;

The error occurs on instantiation, AudioRecord record = new etc.

Has anyone seen this same problem, it seems to be a straight forward request so i´m suprised if this a bug, particular as I can´t get it working with different versions.

I have created the AVDs with Audio Record capabilities. Is there anything else I have to configure?

I have seen a couple of other posts on the same issue, but no replies.

Thanks in advance

Chris


You problem here is probably actually twofold. First, you have to get all of the parameters just right for the AudioRecord, ie, I can see that you tried all the various sampling rates and channel configurations, but did you try different bit depths? If you don't get it all just right, it doesn't work. Furthermore, it would appear that some android devices seem to report the wrong minBufferSize.

But, I think the actual problem you are experiencing is that the AVDs cannot record Audio/Video (even though they may not complain if you configure it so): http://developer.android.com/guide/topics/media/index.html

From paragraph three:

Note that the emulator doesn't have hardware to capture audio or video, but actual mobile devices are likely to provide these capabilities, accessible through the MediaRecorder class.


For me on Samsung Device, it's work with just changing AudioFormat.CHANNEL_IN_MONO

or

AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, 
RECORDER_SAMPLERATE, RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING, bufferSize);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号