问题
I have a series of wave files with individual words, each lasting about 1 second. I want to use C# to concatenate them to one large file at exactly five second intervals. This will save me from having to put the big file through a sound editor and record the start times for each word.
I know how to concatenate files using NAudio and WaveFileWriter.write. Is there a way to either insert a silence for a certain length of time, or to actually append one file at a certain point in a file? I understand there there would be a situation where the file I'm writing to is 11 seconds long, and that I'll want to write the next file at 15 seconds.
I'd be open to converting to mp3 first if that would make things easier. In fact, the big wave file will ultimately be converted to mp3. I'm also open to other tools if that would make more sense.
Many thanks for your help,
Jon
回答1:
When using the NAudio framework you can access the reader to figure out how many bytes of silence you need to write
int bytesPerMillisecond = reader.WaveFormat.AverageBytesPerSecond / 1000;
You can then write whatever number of bytes of silence you need to reach that next multiple of 5 seconds. I'm assuming you can write all zeroes even though that should lead to no sound at all which might sound artificial.
Because of this a better solution might be to make a 5s wav of silence and copy in a section of that. Refer to this nice example for how to write a certain length of a wave:
http://mark-dot-net.blogspot.com/2009/09/trimming-wav-file-using-naudio.html
回答2:
I may not understand the question correctly, but if I do this may work for you. It sounds like you should be able to record a stock "silent file" of whatever length you wish (1 sec, 1/2 sec) using some sound recorder. Then, you could use NAudio to concatenate as many copies of it as you need to provide the amount of silence you want between words. In other words, say you have a 1/2 second silence. You could build word1.wav + silence.wav + silence.wav + word2.wav for a full second of silence between word1 and word2. The length of the silent file would depend on how much precision you needed between words, and you would just have to deploy this silent file with your application.
来源:https://stackoverflow.com/questions/8017480/concatenate-wave-files-at-5-second-intervals