very poor quality of audio recorded on my droidx using MediaRecorder, why?

前端 未结 5 1874
予麋鹿
予麋鹿 2020-12-09 22:48

my project requires me to be able to record audio on an android device. i implemented solution using the MediaRecorder() but the recorded audio is in a terrible quality. wha

5条回答
  •  粉色の甜心
    2020-12-09 23:10

    Try this code:

    MediaRecorder recorder = new MediaRecorder();
    File outputFile = new File(Environment.getExternalStorageDirectory(), "audio.3gp");
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setAudioEncodingBitRate(16);
    recorder.setAudioSamplingRate(44100);
    recorder.setOutputFile(outputFile.getAbsolutePath());
    recorder.prepare();
    recorder.start();
    

    You are going to get some improvement but don't expect too much. You can always try to save uncompressed by using the RehearsalAudioRecord class from this OpenSource project

    http://rehearsalassist.svn.sourceforge.net/viewvc/rehearsalassist/android/releases/RehearsalAssistant_0_8_2/src/urbanstew/RehearsalAssistant/

    The way to implement the class into your project is very simple. You just need to replace your MediaRecorder by:

    RehearsalAudioRecorder recorder = new RehearsalAudioRecorder(RehearsalAudioRecorder.RECORDING_UNCOMPRESSED, MediaRecorder.AudioSource.MIC, 44100, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT);
    recorder.setOutputFile(outputFile.getAbsolutePath());
    recorder.prepare();
    recorder.start();
    

    You will be able to record WAVE files which are quite large but if you require quality is the only way to go. Please note that in older devices this code could

提交回复
热议问题