How to concatenate WAV files in C#

我怕爱的太早我们不能终老 提交于 2019-12-30 09:58:13

问题


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. :)


回答1:


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).




回答2:


If you only need to do this once then your best bet is to use some software specifically for the task. Praat or audacity will do this (join or merge two tracks).

Praat can also be scripted so it is possible to script Praat and then call Praat and the script from within a .Net application.

Rob




回答3:


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.




回答4:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!