<AudioRecord> “Could not get audio input for record source 1”

I’ve been having this issue with initializing AudioRecord for Android. I searched for quite a while on the web with no success.

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.

  • Mechanism for apps to display their image content in native 4k
  • Loading html file from local folder into webview
  • Masked Input Using EditText Widget in Android
  • How to make Android Studio download dependencies sources and javadoc?
  • Android DownloadManager API - opening file after download?
  • Android - howto pass data to the Runnable in runOnUiThread?
  • 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];
    }
    ...
    

    However, the object (this.recorder) failed to be initialized. The following is from the log using DDMS:

    AUDIO-BUFFER-SIZE(3253): 4160
    AudioRecord(3253): set(): sampleRate 8000, channels 16, frameCount 2080
    AudioPolicyManager(2175): getInput() inputSource 1, samplingRate 8000, format 1, channels 10, acoustics 0
    AudioFlinger(2175): openInput() openInputStream returned input 0x0, SamplingRate 8000, Format 1, Channels 10, acoustics 0, status -17
    AudioRecord(3253): Could not get audio input for record source 1
    AudioRecord-JNI(3253): Error creating AudioRecord instance: initialization check failed.
    AudioRecord-Java(3253): [ android.media.AudioRecord ] Error code
    -20 when initializing native AudioRecord object.

    Any help please? Many thanks!

  • backing up android device using adb
  • Android. WebView and loadData
  • How to display a Yes/No dialog box on Android?
  • How to change the hint size of TextInputLayout
  • RelativeLayout and ViewStub inflation
  • What's the height of the Android Toolbar?
  • 7 Solutions collect form web for “<AudioRecord> “Could not get audio input for record source 1””

    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.

    Had the same error, till I restarted the device.

    It seems that on my Galaxy S the native impl is buggy: several times acquiring and releasing an AudioRecorder (during whole phone uptime) causes that error.

    After using audio recorder, you must stop and release it. Then when you init the audio recorder the next time, it’s ok.

    Hi I’ve had the very same issue while trying to initialize an AudioRecord object and the solution I’ve found was to test the configurtion parameter before actually trying to instantiate the current AudioRecord object. Here is the rouine I’ve used:

        /**
     * Scan for the best configuration parameter for AudioRecord object on this device.
     * Constants value are the audio source, the encoding and the number of channels.
     * That means were are actually looking for the fitting sample rate and the minimum
     * buffer size. Once both values have been determined, the corresponding program
     * variable are initialized (audioSource, sampleRate, channelConfig, audioFormat)
     * For each tested sample rate we request the minimum allowed buffer size. Testing the
     * return value let us know if the configuration parameter are good to go on this
     * device or not.
     * 
     * This should be called in at start of the application in onCreate().
     * 
     * */
    public void initRecorderParameters(int[] sampleRates){
    
        for (int i = 0; i < sampleRates.length; ++i){
            try {
                Log.i(TAG, "Indexing "+sampleRates[i]+"Hz Sample Rate");
                int tmpBufferSize = AudioRecord.getMinBufferSize(sampleRates[i], 
                                AudioFormat.CHANNEL_IN_MONO,
                                AudioFormat.ENCODING_PCM_16BIT);
    
                // Test the minimum allowed buffer size with this configuration on this device.
                if(tmpBufferSize != AudioRecord.ERROR_BAD_VALUE){
                    // Seems like we have ourself the optimum AudioRecord parameter for this device.
                    AudioRecord tmpRecoder = new AudioRecord(MediaRecorder.AudioSource.MIC, 
                                                            sampleRates[i], 
                                                            AudioFormat.CHANNEL_IN_MONO,
                                                            AudioFormat.ENCODING_PCM_16BIT,
                                                            tmpBufferSize);
                    // Test if an AudioRecord instance can be initialized with the given parameters.
                    if(tmpRecoder.getState() == AudioRecord.STATE_INITIALIZED){
                        String configResume = "initRecorderParameters(sRates) has found recorder settings supported by the device:"  
                                            + "\nSource   = MICROPHONE"
                                            + "\nsRate    = "+sampleRates[i]+"Hz"
                                            + "\nChannel  = MONO"
                                            + "\nEncoding = 16BIT";
                        Log.i(TAG, configResume);
    
                        //+++Release temporary recorder resources and leave.
                        tmpRecoder.release();
                        tmpRecoder = null;
    
                        return;
                    }                   
                }else{
                    Log.w(TAG, "Incorrect buffer size. Continue sweeping Sampling Rate...");
                }
            } catch (IllegalArgumentException e) {
                Log.e(TAG, "The "+sampleRates[i]+"Hz Sampling Rate is not supported on this device");
            }
        }
    }
    

    I Hop this help.

    Dickwan

    This is also affecting Sansung Galaxy tabs GT-P1000 and later 10.1 one

    This bug is pretty hard to reproduce and a reboot is the only way I found to escape this bad state …

    Is there a bug tracker to follow at samsung ?

    If you did not take Record_Audio permission then take it even than you getting error then switch off your mobile than switch on again then run your app.

    I think the audio hardware cannot support up to 10 channels, which you set as input, so try to use 2 channels, and to see whether it can work.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.