1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| package com.willing.common.utils.audio;
import java.io.*; import java.util.ArrayList;
public class AudioConcatUtil {
public static String concatMp3(ArrayList<String> audioLocations,String targetLocation) throws IOException { File out = null; FileInputStream fis = null; FileOutputStream fos = null; try { out = new File(targetLocation); fos = new FileOutputStream(targetLocation,true); for (String audioLocation : audioLocations) { fis = new FileInputStream(audioLocation); int len = 0; byte[] buf = new byte[fis.available()]; while ((len = fis.read(buf)) != -1){ fos.write(buf, 0, len); } } File file = new File(targetLocation); if (file.exists()||file.length()!=0) { return targetLocation; }else { file.delete(); throw new RuntimeException("文件转换失败:语音文件未生成或生成空语音文件。"); } }catch(FileNotFoundException e){ throw e; } finally { if(fis != null){ fis.close(); } if(fos != null){ fos.close(); } } } }
|