Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android AudioRecord vs. MediaRecorder for recording audio

I want to record human voice on my Android phone. I noticed that Android has two classes to do this: AudioRecord and MediaRecorder. Can someone tell me what's the difference between the two and what are appropriate use cases for each?

I want to be able to analyse human speech in real-time to measure amplitude, etc. Am I correct in understanding that AudioRecord is better suited for this task?

I noticed on the official Android guide webpage for recording audio, they use MediaRecorder with no mention of AudioRecord.

like image 830
stackoverflowuser2010 Avatar asked May 04 '11 16:05

stackoverflowuser2010


People also ask

What is audio capture in Android?

Advertisements. Android has a built in microphone through which you can capture audio and store it , or play it in your phone. There are many ways to do that but the most common way is through MediaRecorder class. Android provides MediaRecorder class to record audio or video.


2 Answers

If you want to do your analysis while recording is still in progress, you need to use AudioRecord, as MediaRecorder automatically records into a file. AudioRecord has the disadvantage, that after calling startRecording() you need to poll the data yourself from the AudioRecord instance. Also, you must read and process the data fast enough such that the internal buffer is not overrun (look in the logcat output, AudioRecord will tell you when that happens).

like image 186
Stephan Avatar answered Sep 21 '22 15:09

Stephan


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

MediaRecorder gives you the max amptitude from last call of getMaxAmplitude() method so you can implement a sound visualizer for example.

So in most cases MediaRecorder is the best choice except those in which you should make some complicated sound processing and you need access to the raw audio stream.

like image 38
Lampapos Avatar answered Sep 21 '22 15:09

Lampapos