音频格式转换成MP3

package com.hfits.modules.app.xczf.util;

import it.sauronsoftware.jave.*;

import java.io.File;

public class Mp3Util {

/**
 * @return mp3文件路径
 */
public void changeToMp3(String sourcePath) {
    File source = new File(sourcePath);
    String targetPath = sourcePath.substring(0,sourcePath.indexOf("."))+".mp3";
    File target = new File(targetPath);
    AudioAttributes audio = new AudioAttributes();
    Encoder encoder = new Encoder();
    audio.setCodec("libmp3lame");
    EncodingAttributes attrs = new EncodingAttributes();
    attrs.setFormat("mp3");
    attrs.setAudioAttributes(audio);

    try {
        encoder.encode(source, target, attrs);
    } catch (IllegalArgumentException e) {
    } catch (InputFormatException e) {
    } catch (EncoderException e) {
    }
}

public  void main(String[] args) {
    String path1 = "E:\\hf-app\\xczfApp\\img\\20190527_172209.amr";
    changeToMp3(path1);
}

}

猜你喜欢

转载自blog.csdn.net/personal_csdn/article/details/90666321