我正在开发一个使用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();
}
当录音机停止时,我用mediaplayer类播放,但结果声音很粗很慢。。可能是什么问题?
根据MediaRecorder文档,AMRNB的采样率为8kHZ,您将其设置为不同的值。我怀疑这就是问题所在。
你能评论这些行并检查这是否适用于你吗:
//recorder.setAudioEncodingBitRate(16);
//recorder.setAudioSamplingRate(44100);