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();
}