以5秒为间隔连接wave文件 [英] Concatenate wave files at 5 second intervals

查看:113
本文介绍了以5秒为间隔连接wave文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列包含单个单词的wave文件,每个持续约1秒.我想使用C#将它们以恰好五秒钟的间隔连接到一个大文件.这样一来,我就不必将大文件通过声音编辑器记录下来,而不必记录每个单词的开始时间.

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.

我知道如何使用NAudio和WaveFileWriter.write连接文件.有没有办法在某个时间段内插入静默,或者在文件中的某个位置实际附加一个文件?我了解会有一种情况,我正在写入的文件长11秒,而我想在15秒时写入下一个文件.

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.

如果这样会使事情变得更容易,我将首先转换为mp3.实际上,大浪文件最终将转换为mp3.如果这样做更有意义,我也可以使用其他工具.

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.

非常感谢您的帮助,

乔恩

推荐答案

使用NAudio框架时,您可以访问阅读器以找出需要写入多少个静默字节

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;

然后,您可以写入达到5秒的下一个倍数所需的任意数量的无声字节.我假设您可以写入全零,即使那根本不会导致听起来可能是虚假的声音.

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.

因此,一个更好的解决方案可能是使5s静音并复制其中的一部分.有关如何编写一定长度的波,请参考以下示例:

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

这篇关于以5秒为间隔连接wave文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆