lame插件:(lame.exe)
链接: https://pan.baidu.com/s/1_B-FFJh7I0IlcyjRqZepKw 提取码: aigr
废话少说,直接贴代码了:
public static final String lamePath = "C:/Users/JSR/Desktop/lame.exe";
/**
* 将源音频文件转换为MP3格式音频文件
* @param source 音频源文件
* @param mp3File MP3格式文件
* @throws InterruptedException
* @throws IOException
*/
public static void toMp3Audio(File source, File mp3File) throws InterruptedException, IOException{
//调用解码器来将wav文件转换为mp3文件
Process p=Runtime.getRuntime().exec(lamePath + File.separator +
" -b 16 " + //16为码率,可自行修改
source.getAbsolutePath() +
" " +
mp3File.getAbsolutePath());
p.getOutputStream().close();//释放进程
p.getInputStream().close();
p.getErrorStream().close();
p.waitFor();
}