有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在Android中将语音录制为mp3

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

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

谁能帮我一下,或者给我一个密码


共 (3) 个答案

  1. # 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)

    并用后缀“.mp3保存文件”

  2. # 2 楼答案

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

  3. # 3 楼答案

    使用此代码这是我的工作:

    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);