I have 2 wav files that I want to concatenate into one file with the two sound tracks.
Is there any api for that task or some built in commands in .NET that can I can use in some genius way to make this task possible?
Many thanks for the help. :)
If I'm not mistaken, you can just append the bytes from the second file to the end of the first. If there is any header data, you'll want to exclude that (see here)
Be advised that you may hear a click or pop between the two clips, as there will be no blending. You could probably get around this by fading (gradually reducing the values for the last few ms to the center value).
The straightforward way would be to interpret the wav file headers, extract the samples and interleave the samples from both files into a new sample stream which you write to a new wav file. You could also add the sample values of both source wav files sample by sample to 'mix' both files into a single track. The wav file format is not that complicated so it should not be too difficult to write this code. Also, there are lots of open source projects containing code to read and write wav files. Note that things can get somewhat trickier of both source wav files have different sample rates. Check this for a description of the wav format.
Yes you can just append the data of the second wav ( excluding its headers) as sais Jon B, but you must also modify the header of the first file to indicate the new length, otherwise some audio players will stop at the end of the first part.
For dynamic concatenation, as you don't know the size of the total wav at the beginning, you can put a fake length on the header of the first file, like put a duration of 10hours for example.
Then the audio player should just wait till you append each data. It works for ffmpeg at least
来源:https://stackoverflow.com/questions/340646/how-to-concatenate-wav-files-in-c-sharp