这里需要用到一个jar包:jave-1.0.1.jar,下载地址的话自己百度吧.
废话不多说直接贴代码:
import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncodingAttributes;
import java.io.File;
public class Test {
/**
* 执行转化过程
*
* @param source
* 源文件
* @param desFileName
* 目标文件名
* @return 转化后的文件
*/
public static File execute(File source, String desFileName)
throws Exception {
File target = new File(desFileName);
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(36000)); //音频比率 MP3默认是1280000
audio.setChannels(new Integer(2));
audio.setSamplingRate(new Integer(44100));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
return target;
}
public static void main(String[] args) throws Exception {
File file = new File("c://1111.wav");
execute(file, "c://111.mp3");
}
}