/** 微信录音amr转mp3
* @param filePath 需要转换的文件
*/
public static String transWxformMp3(String filePath, String targetPath) {
File source = new File(filePath);
// 转换后生成的文件
targetPath += filePath.substring(filePath.lastIndexOf("/"), filePath.lastIndexOf(".")) + ".mp3";
File target = new File(targetPath);
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(36000));
audio.setChannels(new Integer(2)); //1 mono 单声道 2 stereo 立体声
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(EncoderException e){
log.info(e.getMessage());
}
return targetPath;
}
需要jar包:jave-1.0.2.jar