[Audio processing] wav音频文件合并
Posted 小尾巴君
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Audio processing] wav音频文件合并相关的知识,希望对你有一定的参考价值。
package com.audioprocessingbox.myfunc; import java.io.File; import java.io.IOException; import javax.sound.sampled.UnsupportedAudioFileException; import com.audioprocessingbox.utils.WavFile; import com.audioprocessingbox.utils.WavFileException; public class AppCombFiles { private static final long sampleRate = 16000; public static void main(String[] arg) throws UnsupportedAudioFileException { try { int[] postbuffer = new int[0], newbuffer = new int[0], buffer; WavFile wavFile; for(int i = 103; i < 111; i++) { wavFile = WavFile.openWavFile(new File("/Users/karl/Work/database/speaker/certainSpeaker/" + i + ".wav")); if(sampleRate != wavFile.getSampleRate()) { throw new IllegalArgumentException("The sample rate for this file is different than Recognito‘s " + "defined sample rate : [" + wavFile.getSampleRate() + "]"); } //Read wav data into int array int nframes = (int) wavFile.getNumFrames(); buffer = new int[nframes]; wavFile.readFrames(buffer, nframes); wavFile.close(); //Combine two int array newbuffer = new int[postbuffer.length + buffer.length]; System.arraycopy(postbuffer, 0, newbuffer, 0, postbuffer.length); System.arraycopy(buffer, 0, newbuffer, postbuffer.length, buffer.length); postbuffer = new int[postbuffer.length + buffer.length]; postbuffer = newbuffer; } WavFile saveFile = WavFile.newWavFile(new File("/Users/karl/Work/javawork/combine.wav"), 1, postbuffer.length, 16, sampleRate); saveFile.writeFrames(postbuffer, postbuffer.length); saveFile.close(); System.out.println(postbuffer.length / sampleRate); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (WavFileException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
以上是关于[Audio processing] wav音频文件合并的主要内容,如果未能解决你的问题,请参考以下文章
JavaCV音视频开发宝典:基于JavaCV实现wav音频直播服务,wav在线FM电台直播服务,无需流媒体服务,浏览器原生audio标签直接播放wav直播音频
JavaCV音视频开发宝典:基于JavaCV实现wav音频直播服务,wav在线FM电台直播服务,无需流媒体服务,浏览器原生audio标签直接播放wav直播音频
JavaCV音视频开发宝典:基于JavaCV实现wav音频直播服务,wav在线FM电台直播服务,无需流媒体服务,浏览器原生audio标签直接播放wav直播音频