zoukankan      html  css  js  c++  java
  • [Audio processing] wav音频文件合并

    合并多个文件,需要包含1、文件读取和写入功能,2、数组合并

    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();
            }
        }
    }
     
  • 相关阅读:
    U3D不同平台载入XML文件的方法——IOS MAC Android
    C++使用规范小记
    设置角色对象可见性
    编辑器菜单操作
    U3D资源动态加载异步方案探究
    Animation动画
    Unity3D失去焦点时继续渲染
    C#打开当前目录
    组件模式代码实践(C#版本)
    Unity3D批处理脚本
  • 原文地址:https://www.cnblogs.com/littletail/p/5281684.html
Copyright © 2011-2022 走看看