14

I am creating one application which play recorded file on Android to iphone and vice-versa.

now I am using ,

        audioRecorder = new MediaRecorder();
        audioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

file recorded using this code having size 85 kb /15 sec and a very poor quality.

if I use ,

        audioRecorder = new MediaRecorder();
        audioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
        audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

then file size is 25kb/15 sec and quality much better than aac. but problem is that AMR is not playable in iPhone.

So please suggest recording schema for Android having better quality, affordable size and can play on iPhone also.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
PrvN
  • 2,385
  • 6
  • 28
  • 30

2 Answers2

18

Increase the recorder.setAudioEncodingBitRate(value) if you want to change the quality.

recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setAudioEncoder(MediaRecorder.getAudioSourceMax());
recorder.setAudioEncodingBitRate(16);
recorder.setAudioSamplingRate(44100);
recorder.setOutputFile(path);
recorder.prepare();
recorder.start(); 

EDIT:

Another option is to add a converter to your app. Convert AMR to AAC.

StarPinkER
  • 14,081
  • 7
  • 55
  • 81
  • Thanks Jermaine, audioRecorder.setAudioSamplingRate(44100); audioRecorder.setAudioEncodingBitRate(96000); try this but having much noise in sound. – PrvN Feb 20 '13 at 06:31
  • Try to adjust the sampling rate and the bit rate. and find a better place to record. – StarPinkER Feb 20 '13 at 07:01
  • 12
    The bit rate is measured in bits per second, not kb per second, so should be around 128000 rather than 16 as shown here (a value of 16 would correspond to bit depth). – arlomedia Oct 27 '15 at 00:54
  • 5
    ``recorder.setAudioEncoder(MediaRecorder.getAudioSourceMax());`` crashes the app on my side; however ``recorder.setAudioEncodingBitRate(128000);`` works almost perfectly. – Sbonelo Feb 09 '18 at 07:05
  • Get max causes "Invalid audio encoder". Android 8.1. – Damn Vegetables Jul 17 '18 at 06:55
  • EncodingBitRate is too small. Quality of audio is too bad. Use higher EncodingBitRate – coolcool1994 Sep 13 '20 at 22:15
5

This link is very useful: Android supported media formats

This section gives us more information about audio and video formats.

user812786
  • 4,302
  • 5
  • 38
  • 50
SubbaReddy PolamReddy
  • 2,083
  • 2
  • 17
  • 23