android 录音amr格式转换,android – 以AMR文件格式录制音频
我想以AMR文件格式录制音频.我目前正在使用波纹管代码来录制音频:outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "Sample.3gp";myRecorder = new MediaRecorder();myRecorder.setAudioSource(MediaRecorder.AudioS
我想以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文件?
将outputfile更改为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);
解决方法:
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");
关键点:
>输出文件名使用“.amr”后缀.输出格式使用OutputFormat.AMR_NB参数.
> Encorder使用AudioEncoder.AMR_NB
参数.
标签:android,audio-recording,mediarecorder
来源: https://codeday.me/bug/20190519/1138770.html
更多推荐
所有评论(0)