Skip to content

Instantly share code, notes, and snippets.

@JetXing
Created September 10, 2015 01:29
Show Gist options
  • Select an option

  • Save JetXing/8eae6cfdcc5b15dfe535 to your computer and use it in GitHub Desktop.

Select an option

Save JetXing/8eae6cfdcc5b15dfe535 to your computer and use it in GitHub Desktop.
AudioEncodingBitRate
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment