【发布时间】:2014-10-31 13:34:40
【问题描述】:
我想以 AMR 文件格式录制音频。我目前正在使用下面的代码来录制音频:
outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "Sample.3gp";
myRecorder = new MediaRecorder();
myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myRecorder.setOutputFile(outputFile);
但它会生成 .3gp 文件。如何获取 .amr 文件? 将输出文件更改为 Sample.amr 有效。但这是正确的方法吗?请帮助
编辑 现在解决了
这是我的愚蠢错误:我使用了myRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
应该是-
myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
所以下面的代码适用于以 AMR 格式录制:
outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "Sample.amr";
myRecorder = new MediaRecorder();
myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
myRecorder.setOutputFile(outputFile);
【问题讨论】:
标签: android audio-recording mediarecorder