我正在开发一个使用Mediarecorder类记录声音的Android应用程序 以下是我的代码中的一部分:
public void start() throws IOException {
String state = android.os.Environment.getExternalStorageState();
if(!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
throw new IOException("SD Card is not mounted. It is " + state + ".");
}
// make sure the directory we plan to store the recording in exists
File directory = new File(path).getParentFile();
if (!directory.exists() && !directory.mkdirs()) {
throw new IOException("Path to file could not be created.");
}
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setAudioEncodingBitRate(16);
recorder.setAudioSamplingRate(44100);
try {
recorder.setOutputFile(path);
} catch (IllegalStateException e) {
e.printStackTrace();
}
recorder.prepare();
recorder.start();
}
当录音机停止时,我使用媒体播放器类播放它,但结果声音很厚很慢......可能是什么问题?
答案 0 :(得分:0)
根据MediaRecorder documentation,AMRNB的采样率为8kHZ,您将其设置为不同的值。我怀疑这是问题所在。
你能评论这些行并检查它是否适合你:
//recorder.setAudioEncodingBitRate(16);
//recorder.setAudioSamplingRate(44100);