Poor sound quality when recording / playing sound - Android SDK

I have a problem when I try to record and then play the file that was just recorded. I can record and play sound, but the quality stinks. Its not just bad, it’s very difficult to listen to and a bit like a computer’s voice. I am using andriod SDK emulator. The code that sets up the entry is as follows:

MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(path); recorder.prepare(); recorder.start(); 

And the code that plays the file later looks like this:

 MediaPlayer mp = new MediaPlayer(); mp.reset(); mp.setDataSource(path); mp.prepare(); mp.start(); 

I don’t know which part makes the audio file sound really bad, or if only its emulator does it badly and that it will work on a real phone.

+6
android android-emulator audiorecord
source share
4 answers

You are talking about two different objects, AudioRecorder and MediaRecorder.

+1
source share

Try these

 recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); recorder.setAudioChannels(2); recorder.setAudioEncodingBitRate(128); recorder.setAudioSamplingRate(44100); 

If you find that this code failure on Android devices is low, try removing setAudioChannels and setAudioSamplingRate.

+4
source share

It is not just an emulator; this also sounds bad on my Nexus 10.

As in Mohit marwal's answer, you can set the sample rate and bit rate. 44100 is the standard CD quality sampling rate. Most commercial audio recordings are encoded at least 128,000 bits per second (not kilobits per second, as shown in Mohit's answer). So these would be good starting values. In addition, you should use only one channel to cut your file size in half if you do not have a stereo microphone and do not need to record in stereo.

 recorder.setAudioChannels(1); recorder.setAudioEncodingBitRate(128000); recorder.setAudioSamplingRate(44100); 

When I set these values, the file size and quality increase, but still not at the level that I would prefer. Perhaps the remaining noise from a bad microphone on my device, but I did not test it with an external microphone or compared other devices.

+2
source share

AudioRecord takes many arguments that affect the quality of the recording.

Try installing them in the constructor:

  • Audio Source: MIC
  • Sampling Rate: 16000
  • Number of Channels: CHANNEL_CONFIGURATION_MONO
  • Format: ENCODING_PCM_16BIT
  • Buffer size: 16000 * 30 (buffer 30 seconds)

Code example:

 recorder = new AudioRecord( MediaRecorder.AudioSource.MIC, 16000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, 16000*30); 
0
source share

All Articles