Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to record audio file in Android

Tags:

I am working in android. How can I record an audio file through microphone, and how can I save the recorded file in the emulator?

like image 796
ifaim Avatar asked Apr 17 '11 20:04

ifaim


People also ask

Can I record an MP3 on my Android phone?

You can record audio on Android using an easy-to-use built-in audio recording app on most devices, though the exact app tends to differ device to device.

Can you record external audio on Android?

QUICK ANSWERUse your phone's microphone and an audio recorder app to record external audio on Android. You can use the phone's built-in screen recorder feature or download an app from the Google Play Store to record internal audio.


1 Answers

It is easy to record audio in Android. What you need to do is:

1) Create the object for media record class : MediaRecorder recorder = new MediaRecorder();

2) In the emulator, you're unable to store the recorded data in memory, so you have to store it on the SD Card. So, first check for the SD Card availability: then start recording with the following code.

String status = Environment.getExternalStorageState(); if(status.equals("mounted")){    String path = your path; }  recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(path); recorder.prepare(); recorder.start(); 

3) To stop, override stop method of activity

 recorder.stop();  recorder.release(); 
like image 86
krupa parekh Avatar answered Oct 21 '22 09:10

krupa parekh