直接上代码:
public class AudioUtils {
/**
* 将一个amr文件转换成mp3文件
*
* @param amrFile
* @param mp3File
* @throws IOException
*/
public static void amr2mp3(String amrFile, String mp3File) throws IOException {
File source = new File(amrFile);
File target = new File(mp3File);
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 (Exception e) {
}
}
}
以上代码是利用jave.jar实现的
结果:windows下可以正常转MP3,可是在linux下转的MP3都是0字节!