androidvoicerecording

How to Record Voice in android?


I am trying to record the voice in android But it will create the .mp3 file on the path (sdcard/filename) But when i run this file it doesen't play because it doesn't record the voice.

Here is My code

public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()){
        case(R.id.Button01):
            try {
                //audio.start();
                startRecord();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        case(R.id.Button02):
            //audio.stop();
            stopRecord();
        }

    }
     private void startRecord() throws IllegalStateException, IOException{
           // recorder = new MediaRecorder(); 
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);  //ok so I say audio source is the microphone, is it windows/linux microphone on the emulator? 
            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
            recorder.setOutputFile("/sdcard/Music/"+System.currentTimeMillis()+".amr"); 
            recorder.prepare(); 
            recorder.start();      
        }

        private void stopRecord(){
            recorder.stop();
          //recorder.release();
        }



}

Manifest file

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Solution

  • Refer to the Android Audio Capture documentation for recording audio and playing back the recorded audio.