【问题标题】:Record voice as mp3 in Android在 Android 中将语音录制为 mp3
【发布时间】:2015-12-10 20:53:56
【问题描述】:

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

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

谁能帮帮我或给我一个代码?

【问题讨论】:

标签: java android audio mp3 mediarecorder


【解决方案1】:

Mp3 编码器在 android 中不可用,但是可以使用 Libav/FFMPeg 和 mp3 LAME 对 mp3 进行编码,您可以找到示例代码 here

【讨论】:

    【解决方案2】:

    使用此代码,这对我有用:

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

    【讨论】:

      【解决方案3】:

      安卓现在正式支持MP3:

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

      核心媒体格式:


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


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


      您可以将其用作:

      mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

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

      【讨论】:

      • 这是错误的。 MP3 不支持作为编码器(录制),您可以在自己的图片中看到小点(缺少表格标题)。重要的是 AudioEncoder。 OutputFormat 和扩展名无关;如果愿意,您可以将音频文件命名为 .jpg。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-25
      • 2012-08-12
      • 2012-01-06
      • 2013-03-24
      • 1970-01-01
      相关资源
      最近更新 更多