使用 Naudio 从 MP3 读取音频数据

发布于 2024-10-07 23:36:27 字数 704 浏览 0 评论 0原文

我想要分割 mp3 文件的音频数据并对每个块执行FFT 转换

到目前为止,我从音频流中读取的所有尝试都没有成功。 这是我上次尝试的代码(它使用 wav 文件),

        using (var ms = File.OpenRead("reggae.wav"))
         using (var rdr = new WaveFileReader(ms)) 
         {
             int steps = 100;
             int stepSize = (int)rdr.Length / steps;

             byte[][] audData = new byte[steps][];


             for (int i = 0; i < 10; i++)
             {
                 audData[i] = new byte[stepSize];
                 rdr.Read(audData[i], i * steps, stepSize);
             }

         }

使用此代码我得到一个数组越界异常。

我必须使用哪种流以及如何从中读取数据?

是否有naudio api 的文档

I want to split the audio data of a mp3 file and perform an FFT transformation on each of the chunks.

All of my attempts to read from the audio stream did not work so far.
Here is the code for my last attempt (it uses a wav file)

        using (var ms = File.OpenRead("reggae.wav"))
         using (var rdr = new WaveFileReader(ms)) 
         {
             int steps = 100;
             int stepSize = (int)rdr.Length / steps;

             byte[][] audData = new byte[steps][];


             for (int i = 0; i < 10; i++)
             {
                 audData[i] = new byte[stepSize];
                 rdr.Read(audData[i], i * steps, stepSize);
             }

         }

I get an array out of bounds exception with this code.

What kind of streams do I have to use and how do I read the data from it?

Is there any documentation for the naudio api?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀里藏娇 2024-10-14 23:36:27

数组越界异常是由于您向 Read 方法传递了非零偏移值而引起的。应该是:

rdr.Read(audData[i], 0, stepSize);

网络上有几篇文章解释了如何在 NAudio 中执行不同的操作

有关将 FFT 与 NAudio 结合使用的示例,请查看 NAudio 源代码中的 WpfDemo 应用程序,以及 .NET 录音机应用程序 源代码(希望很快就会出现另一篇关于 Coding4Fun 的文章)。

the array out of bounds exception is caused by you passing in a non-zero value for offset to the Read method. It should be:

rdr.Read(audData[i], 0, stepSize);

There are several articles on the web explaining how to do different things in NAudio

For examples of using FFT with NAudio, look at the WpfDemo app in the NAudio source code, and also at the .NET voice recorder application source code (hopefully another article on Coding4Fun will appear shortly).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文