1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > android 录音amr格式转换 android – 以AMR文件格式录制音频

android 录音amr格式转换 android – 以AMR文件格式录制音频

时间:2021-05-15 19:33:25

相关推荐

android 录音amr格式转换 android  – 以AMR文件格式录制音频

我想以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/0519/1138770.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。