c# - How to join 2 or more .WAV files together programatically? -


i need ability join 2 or more .wav files in 1 .wav file. must programatically, using c# (3rd-party products not option). know of system.media.soundplayer class, not looking play the .wav, create it.

thanks in advance.

here's basic wav concatenation function built using naudio. ensure data chunks concatenated (unlike code example in this codeproject article linked in answer). protect against concatenating wav files not share same format.

public static void concatenate(string outputfile, ienumerable<string> sourcefiles) {     byte[] buffer = new byte[1024];     wavefilewriter wavefilewriter = null;      try     {         foreach (string sourcefile in sourcefiles)         {             using (wavefilereader reader = new wavefilereader(sourcefile))             {                 if (wavefilewriter == null)                 {                     // first time in create new writer                     wavefilewriter = new wavefilewriter(outputfile, reader.waveformat);                 }                 else                 {                     if (!reader.waveformat.equals(wavefilewriter.waveformat))                     {                         throw new invalidoperationexception("can't concatenate wav files don't share same format");                     }                 }                  int read;                 while ((read = reader.read(buffer, 0, buffer.length)) > 0)                 {                     wavefilewriter.writedata(buffer, 0, read);                 }             }         }     }         {         if (wavefilewriter != null)         {             wavefilewriter.dispose();         }     }  } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -