我想用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);发布于 2014-10-31 13:50:35
请参阅下面代码中的android OutputFormat文档尝试:
Log.i(TAG,"Record start");
String outputFile;
MediaRecorder myRecorder;
outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "Sample.amr";
Log.i(TAG,"file name: " + outputFile);
myRecorder = new MediaRecorder();
myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
myRecorder.setOutputFile(outputFile);
try {
myRecorder.prepare();
myRecorder.start();
} catch (IOException e) {
e.printStackTrace();
}
try {
Thread.sleep(30*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
myRecorder.stop();
myRecorder.release();
Log.i(TAG,"Record finished");要点:
https://stackoverflow.com/questions/26675988
复制相似问题