my project requires me to be able to record audio on an android device. i implemented solution using the MediaRecorder() but the recorded audio is in a terrible quality. wha
The big problem I had in my audio recording quality was that I set the bit rate way too low at 16. 16 is a value that generally corresponds to bit depth, not bit rate. Bit rate is usually listed as kbps, but MediaRecorder.setAudioEncodingBitRate() take bps (note no "k"). Try this:
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(...);
recorder.setAudioEncoder(...);
final int bitDepth = 16;
final int sampleRate = 44100;
final int bitRate = sampleRate * bitDepth;
recorder.setAudioEncodingBitRate(bitRate);
recorder.setAudioSamplingRate(sampleRate);
recorder.setOutputFile(...);
recorder.prepare();
recorder.start();
// stop
recorder.stop();
recorder.reset();
recorder.release();
You'll need to check supported media formats to figure out the correct matchings of format (audio encoder), container (output format), sampling rate (usually given in kHz but passed to MediaRecorder.setSamplingRate() as just Hz), and bit rate (usually given in kbps). Note that not all formats in the documentation have specified bit rates; using the method in the code above should give a fair guess at the proper bit rate in that case.
Thanks to @StarPinkER, @PrvN, @arlomedia in this SO answer for helping me clear this up.