How to adjust microphone volume in android?

user1206329 picture user1206329 · Aug 29, 2012 · Viewed 24.8k times · Source

I want to recorder the sound, but the mic (microphone) input sound is too loud, and I want to adjust the mic volume, would someone help me? The following is the main code:

private int audioSource = MediaRecorder.AudioSource.MIC;

private static int sampleRateInHz = 8000;

private static int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_MONO;

private static int audioFormat = AudioFormat.ENCODING_PCM_16BIT;

audioRecord = new AudioRecord(audioSource, sampleRateInHz,channelConfig, audioFormat, bufferSizeInBytes);
audioManager.setSpeakerphoneOn(false);

Answer

Ion Aalbers picture Ion Aalbers · Aug 29, 2012

When the microphone is open, it used the volume of the AudioManager.STREAM_MUSIC.

Try to increase this volume and check if the microphone volume also increased.

With:

AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.setStreamVolume(AudioManager.STREAM_MUSIC, yourVolume, 0);