最近在做语音IVR的时候需要对通话进行录音,主要用到了MediaRecorder类,实现代码如下:
MediaRecorder mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"ivr_record");
if(!dir.exists()){
dir.mkdirs();
}
mFileName = new File(dir,"ivr_"+System.currentTimeMillis()+".3gp").getAbsolutePath();
Log.i(TAG, "start recording:"+mFileName);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(TAG, "