Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which audio format to use in android to store recording

I am developing application which records voice from mic, currently I am storing recorded audio in wave file but size of wave is becoming an issue.

I came to know that android do not have mp3 decoder is it true? What would I do to store recorded audio in compressed form?

I am using AudioRecord class for recording and don't want to use MediaRecorder.

like image 490
DCoder Avatar asked May 06 '14 10:05

DCoder


1 Answers

Using AudioRecord does not give you many options. It stores audio in PCM format only. You can lower size only by setting channel config to CHANNEL_IN_MONO and audio format to ENCODING_PCM_8BIT. Additionally, you can try to extend AudioRecord class and override read() method. Then you must convert audio yourself but that's not recommended.

I know you don't want this but the best option would be refactoring your code to use MediaRecorder. Here is example from reference documentation:

MediaRecorder recorder = new MediaRecorder();
 recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
 recorder.setOutputFile(PATH_NAME);
 recorder.prepare();
 recorder.start();   // Recording is now started
 ...
 recorder.stop();
 recorder.reset();   // You can reuse the object by going back to setAudioSource() step
 recorder.release(); // Now the object cannot be reused

On this site http://developer.android.com/guide/appendix/media-formats.html#core you have nice table presenting all supported formats taking into considerations Android versions. Try these AAC LC, AMR-NB, AMR-WB. Except sizes check the quality.

like image 53
Damian Petla Avatar answered Nov 03 '22 21:11

Damian Petla