title: Android AudioRecord - Record Audio with small file size
body: <p>I'm working on Audio recorder app using <code>AudioRecord</code> not <code>MediaRecorder</code>.
  I'm writing this code to record:</p>
  
  <pre><code>private void startRecord(){
  
          File file = new File(Environment.getExternalStorageDirectory(), "test.pcm");
  
          try {
              file.createNewFile();
  
              OutputStream outputStream = new FileOutputStream(file);
              BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
              DataOutputStream dataOutputStream = new DataOutputStream(bufferedOutputStream);
  
              int minBufferSize = AudioRecord.getMinBufferSize(8000,
                      AudioFormat.CHANNEL_CONFIGURATION_MONO,
                      AudioFormat.ENCODING_PCM_16BIT);
  
              short[] audioData = new short[minBufferSize];
  
              AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
                      8000,
                      AudioFormat.CHANNEL_CONFIGURATION_MONO,
                      AudioFormat.ENCODING_PCM_16BIT,
                      minBufferSize);
  
              audioRecord.startRecording();
  
              while(recording){
                  int numberOfShort = audioRecord.read(audioData, 0, minBufferSize);
                  for(int i = 0; i &lt; numberOfShort; i++){
                      dataOutputStream.writeShort(audioData[i]);
                  }
              }
  
              audioRecord.stop();
              dataOutputStream.close();
  
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      }
  </code></pre>
  
  <p>It's working fine. but, i have a large file size. I recorded about 1 min and i had file with size about 1.2M.</p>
  
  <p>I tried to use <code>MediaRecorder</code> using this code:</p>
  
  <pre><code>mMediaRecorder = new MediaRecorder();
  
  mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  
  mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  
  mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  
  mMediaRecorder.setOutputFile(fileName);
  
  mMediaRecorder.prepare();
  
  mMediaRecorder.start();
  </code></pre>
  
  <p>It's great and recorded 5 minutes with file size about 500K or less. But, i have to use AudioRecord because i need to apply some task on audio byte by byte.</p>
  
  <p>Can i have the same file size in <code>MediaRecorder</code> when i use <code>AudioRecord</code>?</p>
  
  <p>Thank you very much.</p>