What's good about setAudioEncodingBitRate for voice recording

Hi, I want to use mediaRecorder to record voice. I want to save the amr format.

this.mediaRecorder = new MediaRecorder(); this.mediaRecorder.setAudioChannels(1); this.mediaRecorder.setAudioSamplingRate(8000); this.mediaRecorder.setAudioEncodingBitRate(16); this.mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); this.mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR); this.mediaRecorder.setOutputFile(this.file.getAbsolutePath()); this.mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 

I used this.mediaRecorder.setAudioEncodingBitRate (16), some device is ok

mediaRecorder.setAudioEncodingBitRate (12500), somedevice is fine

but i delete mediaRecorder.setAudioEncodingBitRate some device is ok

so my question is how to get the default AudioEncodingBitRate. which parameter do i need to use?

+6
source share
2 answers

You set AudioEncodingBitRate too low. I made the same mistake :-)

It works:

 MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); if (Build.VERSION.SDK_INT >= 10) { recorder.setAudioSamplingRate(44100); recorder.setAudioEncodingBitRate(96000); recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); } else { // older version of Android, use crappy sounding voice codec recorder.setAudioSamplingRate(8000); recorder.setAudioEncodingBitRate(12200); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); } recorder.setOutputFile(file.getAbsolutePath()); try { recorder.prepare(); } catch (IOException e) { throw new RuntimeException(e); } 

Idea comes from here

plus: read the docs. The setAudioSamplingRate docs say the following:

The sampling rate really depends on the sound recording format, as well as on the capabilities of the platform. For example, the sampling rate supported by the AAC audio coding standard ranges from 8 to 96 kHz, the sampling frequency supported by AMRNB is 8 kHz, and the sampling frequency supported by AMRWB is 16 kHz.

+22
source

I use more complex configurations and give an amazing record result.

 localFileName = getFileName()+".wav"; localFile = new File(localdir, localFileName); mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); mRecorder.setOutputFormat(AudioFormat.ENCODING_PCM_16BIT); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); mRecorder.setAudioChannels(1); mRecorder.setAudioEncodingBitRate(128000); mRecorder.setAudioSamplingRate(44100); mRecorder.setOutputFile(localFile.getPath()); 

however, if you simultaneously record sound at the same time, it has some problems on samsung devices.

[but again, only when you simultaneously play sound and record both together]

+1
source

All Articles