在Android中将语音录制为mp3

时间:2012-07-04 05:45:07

标签: java android audio mp3 mediarecorder

在我的Android应用程序中,我想将我的声音录制为MP3文件。但Android的Media Recorder(支持录音的课程)似乎不支持MP3格式。它似乎只允许3gp和mpeg4文件格式。

recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG4);

任何人都可以帮我或给我一个代码吗?

3 个答案:

答案 0 :(得分:1)

Mp3编码器在android中不可用,但mp3可以使用带有mp3 LAME的Libav / FFMPeg进行编码,你可以找到示例代码here

答案 1 :(得分:0)

使用此代码这对我有用:

MediaRecorder   recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
/*  recorder.setAudioEncodingBitRate(32);
recorder.setAudioSamplingRate(44100);*/
recorder.setOutputFile(file.getPath());
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);

答案 2 :(得分:-1)

现在Android正式支持MP3:

http://developer.android.com/guide/appendix/media-formats.html

核心媒体格式:

格式/编解码器 || 详细信息 || 支持的文件类型/容器格式

MP3 || 单声道/立体声8-320Kbps恒定(CBR)或可变比特率(VBR) || MP3(.mp3)格式

enter image description here

您可以将其用作:

<强> mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

并保存带后缀的文件&#34; .mp3 &#34;