Android AudioRecord vs MediaRecorder for recording audio

I want to record a human voice on my Android phone. I noticed that Android has two classes: AudioRecord and MediaRecorder . Can someone tell me what is the difference between them and what are the suitable use cases for each?

I want to be able to analyze human speech in real time to measure amplitude, etc. Do I understand correctly that AudioRecord is better suited for this task?

I noticed on the official webpage for recording sound , they use MediaRecorder without mentioning AudioRecord.

+68
android audio-recording audiorecord
May 04 '11 at 16:44
source share
3 answers

If you want to perform analysis while recording, you still need to run AudioRecord , since MediaRecorder automatically written to the file. AudioRecord has the disadvantage that after calling startRecording() you need to poll the data yourself from an instance of AudioRecord . In addition, you should read and process the data fast enough so that the internal buffer does not overflow (look in the logcat output, AudioRecord will tell you when this will happen).

+57
May 04 '11 at 19:04
source share

As I understand it, MediaRecorder is a black box that gives a compressed audio file to the output, and AudioRecorder gives you just a raw audio stream, and you have to compress it yourself.

MediaRecorder gives the maximum amplitude from the last call to the getMaxAmplitude() method so that you can implement, for example, a sound visualizer.

Thus, in most cases, MediaRecorder is the best choice, except for those in which you have to perform complex audio processing, and you need access to the raw audio stream.

+20
Oct 07 '13 at 14:29
source share

AudioRecorderer first saves the data in minBuffer, then it is copied from there to a temporary buffer, and in MediaRecorder it is copied to files. In AudioRecorder, we need api setRecordPosition () to copy the saved data to the desired position, while in MediaRecorder the file pointer performs this task to set the marker position. AudioRecorder can be used for those applications that run on the emulator, this can be done by providing a low sampling rate, for example 8000, when using MediaRecorder sound cannot be recorded using the emulator. In AudioRecord, the screen goes to sleep after a while, but in MediaRecorder the screen does not fall asleep.

+13
Apr 15 '13 at 8:33
source share



All Articles