java 将amr文件转为MP3 需要的jar包

时间:2019-11-24 05:09:53
【文件属性】:

文件名称:java 将amr文件转为MP3 需要的jar包

文件大小:18.69MB

文件格式:JAR

更新时间:2019-11-24 05:09:53

java 将amr音频 转MP3

java 将音频文件转为mp3 代码如下: import it.sauronsoftware.jave.AudioAttributes; import it.sauronsoftware.jave.Encoder; import it.sauronsoftware.jave.EncoderException; import it.sauronsoftware.jave.EncodingAttributes; import it.sauronsoftware.jave.InputFormatException; import java.io.File; import java.util.concurrent.atomic.AtomicBoolean; public class AudioConvert { /** * 音频转为Mp3 * @param source 需要转换的音频源文件 * @param desFileName 转换为mp3文件的路径 * @return 返回是否转换成功 */ public static void audioToMp3(File source, String desFileName){ File target = new File(desFileName); AudioAttributes audio = new AudioAttributes(); audio.setCodec("libmp3lame"); audio.setBitRate(new Integer(128000)); audio.setChannels(new Integer(2)); audio.setSamplingRate(new Integer(44100)); EncodingAttributes attrs = new EncodingAttributes(); attrs.setFormat("mp3"); attrs.setAudioAttributes(audio); Encoder encoder = new Encoder(); try { encoder.encode(source, target, attrs); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InputFormatException e) { e.printStackTrace(); } catch (EncoderException e) { e.printStackTrace(); } } public static void main(String[] strs){ File source = new File("C:\\Users\\a\\Desktop\\转换\\2.amr"); audioToMp3(source,"C:\\Users\\a\\Desktop\\转换\\3.mp3"); } }


网友评论