how to record audio file with better quality in android?

核能气质少年 提交于 2019-11-29 17:34:43

问题


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.


回答1:


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.




回答2:


This link is very useful: Android supported media formats

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



来源:https://stackoverflow.com/questions/14973133/how-to-record-audio-file-with-better-quality-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!