[ACCEPTED]-How to record audio file in Android-android-widget

Accepted answer
Score: 25

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

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

2) In the emulator, you're 5 unable to store the recorded data in memory, so 4 you have to store it on the SD Card. So, first 3 check for the SD Card availability: then 2 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 1 stop, override stop method of activity

 recorder.stop();
 recorder.release();
Score: 5

Here is a good tutorial with sample code.

Audio Capture at Android Developer

it 1 includes these steps:

  • Create a new instance of android.media.MediaRecorder.
  • Set the audio source using MediaRecorder.setAudioSource(). You will probably want to use MediaRecorder.AudioSource.MIC.
  • Set output file format using MediaRecorder.setOutputFormat().
  • Set output file name using MediaRecorder.setOutputFile().
  • Set the audio encoder using MediaRecorder.setAudioEncoder().
  • Call MediaRecorder.prepare() on the MediaRecorder instance.
  • To start audio capture, call MediaRecorder.start().
  • To stop audio capture, call MediaRecorder.stop().
  • When you are done with the MediaRecorder instance, call MediaRecorder.release() on it. Calling MediaRecorder.release() is always recommended to free the resource immediately.
Score: 2

Basically, there is no easy way to write 7 audio file as simple WAV file. AudioRecorder produces 6 data in raw Linear PCM format. And Android's 5 API only gives you audio data buffers.

You'll 4 need to create WAV file yourself. What this 3 means for you, is that you need to add all 2 the chunks yourself: RIFF header, FMT and 1 DATA chunks.

Score: 1

I had tried to record the WAV file in android. But 10 somehow, it is only recording the. WAV file 9 in stereo only and you should use the audio 8 recorder with the following parameter

recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
                        RECORDER_SAMPLERATE, AudioFormat.CHANNEL_IN_MONO,RECORDER_AUDIO_ENCODING, bufferSize);

        recorder.startRecording();

and 7 from the recorder, you need to write all 6 the data into one file and also you need 5 to give header information

then just do

recorder.stopRecording();

but 4 I have just one problem in this is even 3 if I give AudioFormat.CHANNEL_IN_MONO..it 2 still record in stereo format. Hope my answer 1 helps you.

More Related questions