C#中的WAV文件自动重复

时间:2021-08-07 19:43:15

I have a 10 second sound effect wave file. What I would like to do is take that file and repeat it n number of times and then save the longer WAV file to disk. This way I can create a much longer background effect rather than auto-repeat on the media player which is a bit stuttered between repeats. I am trying to do this in C#.

我有一个10秒的音效波形文件。我想要做的是获取该文件并重复多次,然后将较长的WAV文件保存到磁盘。通过这种方式,我可以创建更长的背景效果,而不是在媒体播放器上自动重复,这在重复之间有点断断续续。我想在C#中这样做。

4 个解决方案

#1


2  

If you only need to do this with a small number of files, you might as well do it by hand with Audacity.

如果您只需要使用少量文件执行此操作,您也可以使用Audacity手动执行此操作。

#2


3  

That's reasonably easy to do, given the WAV file format - assuming it's uncompressed audio (most WAV files are - or at least, they were last time I had anything to do with them).

考虑到WAV文件格式,这是相当容易做到的 - 假设它是未压缩的音频(大多数WAV文件是 - 或者至少,它们是我们上一次与它们有任何关系)。

There may well be audio APIs you can use to do this without getting stuck into the binary format, but I suspect they'd take as long to learn as just doing it yourself as you're not doing anything particularly complicated.

你可以使用音频API来实现这一目标,而不会陷入二进制格式,但我怀疑他们需要花费很长时间来学习,因为你没有做任何特别复杂的事情。

#3


0  

If you're using .Net 2.0 or higher then you can use the System.Media.SoundPlayer class and specifically its PlayLooping method to achieve what you want with no stuttering. This is preferable to creating a new wav file - it means less disk space for the file and less memory needed to render the sound. In general you should always use buffered techniques like this for audio playback if the sound will be looped or is longer than a few seconds.

如果你使用的是.Net 2.0或更高版本,那么你可以使用System.Media.SoundPlayer类,特别是它的PlayLooping方法来实现你想要的,没有口吃。这比创建新的wav文件更好 - 这意味着文件的磁盘空间更少,渲染声音所需的内存更少。一般情况下,如果声音循环或超过几秒钟,您应该始终使用这样的缓冲技术进行音频播放。

#4


0  

You can do this easily in C# using the NAudio .NET audio library. You would need to use the WaveFileReader and WaveFileWriter classes. You can also use it to create a custom WaveStream that will loop your audio as many times as you want without the need to create a long WAV file.

您可以使用NAudio .NET音频库在C#中轻松完成此操作。您需要使用WaveFileReader和WaveFileWriter类。您还可以使用它来创建自定义WaveStream,它可以根据需要多次循环音频,而无需创建长WAV文件。

#1


2  

If you only need to do this with a small number of files, you might as well do it by hand with Audacity.

如果您只需要使用少量文件执行此操作,您也可以使用Audacity手动执行此操作。

#2


3  

That's reasonably easy to do, given the WAV file format - assuming it's uncompressed audio (most WAV files are - or at least, they were last time I had anything to do with them).

考虑到WAV文件格式,这是相当容易做到的 - 假设它是未压缩的音频(大多数WAV文件是 - 或者至少,它们是我们上一次与它们有任何关系)。

There may well be audio APIs you can use to do this without getting stuck into the binary format, but I suspect they'd take as long to learn as just doing it yourself as you're not doing anything particularly complicated.

你可以使用音频API来实现这一目标,而不会陷入二进制格式,但我怀疑他们需要花费很长时间来学习,因为你没有做任何特别复杂的事情。

#3


0  

If you're using .Net 2.0 or higher then you can use the System.Media.SoundPlayer class and specifically its PlayLooping method to achieve what you want with no stuttering. This is preferable to creating a new wav file - it means less disk space for the file and less memory needed to render the sound. In general you should always use buffered techniques like this for audio playback if the sound will be looped or is longer than a few seconds.

如果你使用的是.Net 2.0或更高版本,那么你可以使用System.Media.SoundPlayer类,特别是它的PlayLooping方法来实现你想要的,没有口吃。这比创建新的wav文件更好 - 这意味着文件的磁盘空间更少,渲染声音所需的内存更少。一般情况下,如果声音循环或超过几秒钟,您应该始终使用这样的缓冲技术进行音频播放。

#4


0  

You can do this easily in C# using the NAudio .NET audio library. You would need to use the WaveFileReader and WaveFileWriter classes. You can also use it to create a custom WaveStream that will loop your audio as many times as you want without the need to create a long WAV file.

您可以使用NAudio .NET音频库在C#中轻松完成此操作。您需要使用WaveFileReader和WaveFileWriter类。您还可以使用它来创建自定义WaveStream,它可以根据需要多次循环音频,而无需创建长WAV文件。