0

I tried to record audio in Android. The quality of the sound using the MediaRecorder really sucks. Is there a way to improve quality? The documentation says, there should be something like "setAudioEncodingBitRate", but I haven't found a way to implement it.

Then I tried writing the sound to a stream using the AudioRecord function. Great quality but pcm-files are too large in size as I want to upload them to a remote server.

Does anybody know how to either

  • improve quality of the AudioRecorder file or
  • compress the pcm on the fly (like mp3 or else).

Any help is mostly appreciated.

Tom Wilke
  • 481
  • 4
  • 4
  • Heres a similar question you can refer to this: [https://stackoverflow.com/questions/1437888/improve-android-audio-recording-quality](https://stackoverflow.com/questions/1437888/improve-android-audio-recording-quality) – Shardul Dec 26 '10 at 14:28
  • Thanks for you quick answer, but I still don't get it. The RingDroid App uses a low quality MediaRecorder. And the RehearsalAssistent doesn't compress the stream. Am I missing something here? – Tom Wilke Dec 26 '10 at 15:22
  • Well to be frank I really haven't tried any of this. I just came across similar question. – Shardul Dec 27 '10 at 16:01
  • So guys, I found the solution: setAudioEncodingBitrate works from 2.2 upwards. I was using 2.1 Stupid me! – Tom Wilke Dec 28 '10 at 11:30

1 Answers1

0

Yes there are a few things you can change with the audio recorder that will improve the quality. Namely the bitrate/sampling rate and the Audio encoder itself.

Here is a snippet of code that I have been using recently to record audio, with the catches setup for you also.

private void startRecording() {
    recorder = new MediaRecorder();

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setAudioEncodingBitRate(16);
    recorder.setAudioSamplingRate(44100);
    recorder.setOutputFile(getFilename());
    recorder.setOnErrorListener(errorListener);
    recorder.setOnInfoListener(infoListener);

    try {
        recorder.prepare();
        recorder.start();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Obviously you will need to call recorder.stop and release it where necessary.

 private void stopRecording() {
    if (null != recorder) {
        recorder.stop();
        recorder.reset();
        recorder.release();
        recorder = null;
    }
}

I still feel there is room for improvement with the quality, so its only a work in progress. Hope that helps!

Phillip Hartin
  • 889
  • 1
  • 13
  • 25