Search code examples
javaandroidaudioamraudiorecord

Recording sound in android



I'd like to know how to record sound for a specific amount of time, without saving it to a file - holding in a byte stream for example. Also, if possible, make it look like an AMR file. I've tried to search google, and also wrote some code myself, but had no success. If you can link me to a page that explains how to do so, or give an example, it would be very nice of you :)

Thanks.


Solution

  • MediaRecorder recorder = new MediaRecorder();
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
    recorder.setOutputFile(fileName);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    
    recorder.prepare();
    recorder.start();
    

    I'm not sure if you can skip the setOutputFile step and keep the recording in memory (probably not).