AMR audio recording

I want to record audio in AMR format. I am currently using the following code to record sound:

outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "Sample.3gp";

myRecorder = new MediaRecorder();
myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myRecorder.setOutputFile(outputFile);

But it generates a .3gp file. How can I get a .amr file? Changing the output file in Sample.amr. But is this the right way? Please, help

CHANGE IT RESOLVED NOW

It was my stupid mistake: I used myRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);

Must be -

myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

So, for recording in AMR format, the following code is used:

outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "Sample.amr";

    myRecorder = new MediaRecorder();
    myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    myRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
    myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    myRecorder.setOutputFile(outputFile);
+4
source share
1 answer

Refer to the android file OutputFormat Try to enter the code:

    Log.i(TAG,"Record start");
    String outputFile;
    MediaRecorder myRecorder;
    outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "Sample.amr";
    Log.i(TAG,"file name: " + outputFile);

    myRecorder = new MediaRecorder();
    myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    myRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
    myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    myRecorder.setOutputFile(outputFile);

    try {
        myRecorder.prepare();
        myRecorder.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        Thread.sleep(30*1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    myRecorder.stop();
    myRecorder.release();
    Log.i(TAG,"Record finished");

Key points:

  • ".amr" . OutputFormat.AMR_NB.
  • AudioEncoder.AMR_NB .
+4

All Articles