/**
	 * 
	 * @param partsPaths 要合成的音频路径数组
	 * @param unitedFilePath 输入合并结果数组
	 */
	public void uniteWavFile(String[] partsPaths, String unitedFilePath) {

			byte byte1[] = getByte(partsPaths[0]);
			byte byte2[] = getByte(partsPaths[1]);

			byte[] out = new byte[byte1.length];
			for (int i = 0; i < byte1.length; i++)
				out[i] = (byte) ((byte1[i] + byte2[i]) >> 1);
			
			try {
				FileOutputStream fos = new FileOutputStream(new File(unitedFilePath));
				fos.write(out);
				fos.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
	}

	private byte[] getByte(String path){
		File f = new File(path);
		InputStream in;
		byte bytes[] = null;
		try {
			in = new FileInputStream(f);
			bytes = new byte[(int) f.length()];
			in.read(bytes);
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return bytes;
	}
	

posted on 2014-04-27 16:20  纯洁的坏蛋  阅读(985)  评论(0编辑  收藏  举报