3

So far I have this: With this code I can configure Media Recorder to record in 3gp, but i need to record in WAV for a later process.

private void setupMediaRecorder() {
    mediaRecorder = new MediaRecorder();
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
    mediaRecorder.setOutputFile(MainActivity.PATH_TEMP_RECORDING);
}

2 Answers2

2

Found it. This configuration works:

    mediaRecorder = new MediaRecorder();
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setOutputFormat(AudioFormat.ENCODING_PCM_16BIT);
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    mediaRecorder.setAudioChannels(1);
    mediaRecorder.setAudioEncodingBitRate(128000);
    mediaRecorder.setAudioSamplingRate(48000);
    mediaRecorder.setOutputFile(MainActivity.PATH_TEMP_RECORDING);
1

The MediaRecorder do not let you record in the lossless format. Instead, AudioRecord is more low-level API for audio recording, while you need to write buffer code and filewriting code yourself. Here is a example of using AudioRecord to write into .pcm file. WAV is basically a container of PCM 2. If you want to write into .wav, you need to write the header yourself, and here is an example of using AudioRecord to write into .wav.

Lynne
  • 454
  • 7
  • 16