我怎样才能层C#两个音频文件? [英] How can I layer two audio files in C#?

查看:164
本文介绍了我怎样才能层C#两个音频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要混合两个音频文件。音频1将是一个静态文件,并使用标记音频2.要清楚我说的是音频标签不ID3标签。

I need to mix two audio files. Audio 1 will be a static file and used to "tag" Audio 2. To be clear I'm talking about an audio tag not an ID3 tag.

有两个基本问题,我不能绕到我的头。

There are two basic problems I can't wrap my head around.

1)如何可以重复音频1当与音频2混合,使得结果是相同的长度音频2

1) How can I repeat Audio 1 when mixed with Audio 2 so that the result is the same length as Audio 2?

2)音频2将是一个MP3,我不希望再带code将其并有可能降低它的质量。

2) Audio 2 will be an MP3 and I don't want to re-encode it and possibly reduce it's quality.

这是如何在C#中进行的库或想法会更加AP preciated。

Any libraries or ideas on how this can be done in C# will be much appreciated.

推荐答案

您可以使用 n音讯以做这个。使用WaveFileReader类做出的WaveStream可以从每个文件(MP3一会需要先转换为PCM - 看到n音讯演示code使用Mp3FileReader的)的读取。然后,我会做一个衍生的WaveStream这一轮循环(即Read方法,当你到源数据的结束,回到开头)。

You can use NAudio to do this. Use the WaveFileReader class to make a WaveStream that can read from each of your files (the MP3 one would need to be converted to PCM first - see the use of Mp3FileReader in the NAudio demo code). Then I would make a derived WaveStream that loops round (i.e. in the Read method, when you get to the end of the source data, go back to the beginning).

然后在一起,使用WaveMixerStream32混合。 (他们将需要先转换为32位 - 使用WaveChannel32做到这一点)。这个类也将让您设定每个文件的音量。最后,使用Wave32To16Stream转换回16位,然后使用WaveFileWriter作最后的文件。然后使用LAME转换成MP3。

Then mix them together, using the WaveMixerStream32. (they will need to be converted to 32 bit first - use the WaveChannel32 to do this). This class will also allow you to set the volume levels of each file. Finally, convert back to 16 bit using the Wave32To16Stream and then use the WaveFileWriter to make your final file. Then use LAME to convert to MP3.

这篇关于我怎样才能层C#两个音频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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