Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android AudioRecord and MediaRecorder

I'm developing an audio processing application where I need to record audio, and then process it to obtain features of that recording. However, I want the audio in a playable format to play it after with MediaPlayer.

I've seen that to record audio to process it it's better to use AudioRecord, because I can get the raw audio from there. But then I can't write the data to a file in a playable format (is there any library to do this in android?).

I used this method to record raw data and then write it into a file: http://andrewbrobinson.com/2011/11/27/capturing-raw-audio-data-in-android/ But when i try to play this file on the device, it is not playable.

Then if I use MediaRecorder I don't know how to decode the data to extract the features. I've been looking at MediaExtractor, but it seams that MediaExtractor doesn't decode the frames.

So.. what's the best way to do this? I imagine that's common in any audio processing application, but I wasn't able to find the way to manage this.

Thanks to your replies.

like image 742
Miquel Avatar asked Oct 08 '12 11:10

Miquel


3 Answers

Using AudioRecord is the right way to go if you need to do any kind of processing. To play it back, you have a couple options. If you're only going to be playing it back in your app, you can use AudioTrack instead of MediaPlayer to play raw PCM streams.

If you want it to be playable with other applications, you'll need to convert it to something else first. WAV is normally the simplest, since you just need to add the header. You can also find libraries for converting to other formats, like JOrbis for OGG, or JLayer for MP3, etc.

like image 173
Geobits Avatar answered Oct 27 '22 13:10

Geobits


For best quality result you have to use AudioRecord class instead of MediaRecorder.
Please have a look to below link:
Need a simple example for audio recording

Also have a look to this link: http://i-liger.com/article/android-wav-audio-recording

like image 39
Imran Zulfiqar Avatar answered Oct 27 '22 13:10

Imran Zulfiqar


If you use AudioRecord object to get the raw audio signal, the next step to save it save as a playable file is not so difficult, you just need to add a WAV Head before the audio data you capture, then you get a .WAV file which you can play it on most mobile phones.

A .WAV file is a file under the RIFF format. the RIFF header for WAV file is 44 byte long and contains the sample rate, sample width and channel counts information. you can get the detail information from here

I did the sample function on Android phones and it worked.

like image 42
Zephyr Avatar answered Oct 27 '22 13:10

Zephyr