views:

65

answers:

1

Hey, I have a problem with andriod programing when I try to record and then play the file that was just recored. I can both record and play the sound but the quality stinks. Its not just bad is really hard to listen to and sound abit like its a computer generated voice... I use the andriod SDK-emulator. The code that sets up the recording looks like this;

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 playing the file later looks like this;

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

I dont know what part that makes the audiofile sound really bad... or if its just the emulator that makes it bad and that it would work on a real phone. I would love some help with this.

/Nick

A: 

AudioRecord takes a variety of arguments that would influence the recording quality.

Try setting these in the constructor:

  • Audio Source: MIC
  • Sample rate: 16000
  • Number of channels: CHANNEL_CONFIGURATION_MONO
  • Format: ENCODING_PCM_16BIT
  • Buffer size: 16000 * 30 (30 second buffer)

Code example:

recorder = new AudioRecord(
                          MediaRecorder.AudioSource.MIC,
                          16000,
                          AudioFormat.CHANNEL_CONFIGURATION_MONO,
                          AudioFormat.ENCODING_PCM_16BIT,
                          16000*30);
Aaron C
Thanks a lot, but got a problem with this, according to;http://developer.android.com/reference/android/media/MediaRecorder.html#MediaRecorder()there should be functions for this, for example "setAudioSamplingRate(int samplingRate)", but I cant use that with my recorder, it just dont exist... Can you give a code-example how you define this?Thanks alot!
Nick3
Sample rate is something that should be set when you first initialized the Recorder. All of the parameters in my answer should be set in the constructor and then left alone for the duration of your recording session.
Aaron C