Search code examples
javaandroidaudiowavpcm

How can I encode in a format that's not supported by Media Recorder?


I am writing an android app that will be a voice recorder app that needs to record a .wav file at a specific setting. It needs to match the following information:

   File Type: Windows PCM
   File extension: .wav
   22050 Hz, 16-bit, Stereo

The file information above is from this file. It is a standard Windows file that our server will play. If the file doesn't match these settings, our server will not interpret the file. I have tried recording like this but it will not work:

        mRecorder = new MediaRecorder();
        SharedPreferences prefs = getSharedPreferences("MyPreference", MODE_PRIVATE);
        int curValue = prefs.getInt("recordCount", 0); // Getting current value of sharedPref
        String fileNameWNum = "Recording" + curValue + ".wav";
        ...
        mRecorder.setOutputFile(fileName);
        mRecorder.setAudioEncoder(ENCODING_PCM_16BIT);
        mRecorder.setAudioSamplingRate(22050);

This method is making a .wav file but not encoding it. Can anyone suggest how I can encode the infomation?

EDIT: This is the file being recorded by my software


Solution

  • Based on the file (Recording 8.wav) that you have shared.

    Property of the file.

    Duration: 00:00:38.08, start: 0.000000, bitrate: 15 kb/s Stream #0:0(eng): Audio: amr_wb (sawb / 0x62776173), 16000 Hz, mono, flt, 13 kb/s (default)

    Please check this reference code for Wav recording on Android and Audio Record Class

    Note : Normal MediaRecorder don't support wav recording in Android.