将mp3数据转换为wav数据C# [英] Converting mp3 data to wav data C#

查看:577
本文介绍了将mp3数据转换为wav数据C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我正在接收字节数组中的mp3数据.我想将该数据转换为wav格式,并将其存储在另一个字节数组中.我在互联网上搜索了mp3到wav的转换器,但它们都支持文件到文件的转换.他们似乎都没有将原始数据作为输入.有什么我可以在C#中实现的方法吗?
这是我要创建的功能的原型.

In my project I am receiving mp3 data in a byte array. I want to convert that data to wav format and store it in another byte array. I searched internet for mp3 to wav converters but all of them support file to file conversion. None of them seems to take raw data as inputs. Is there any way I can achieve this in C# ?
Here is the protoype of the function I am trying to create.

   bool ConvertToWav(byte[] buffer){
      //Do some processing and store the wav data in buffer2
      Buffer.BlockCopy(buffer2,0,buffer,0,buffer.Length-1);
   }

推荐答案

这是比较晚的响应,但我自己才知道. 有一个名为NAudio的NuGet程序包, https://www.nuget.org/packages/NAudio/ 这为您要做的事情提供了很棒的功能.

This is quite the late response but I just figured it out myself. There is this NuGet package called NAudio, https://www.nuget.org/packages/NAudio/ This provides awesome functionality for what you want to do.

    using NAudio.Wave;        

    private static void ConvertMp3ToWav(string _inPath_, string _outPath_)
    {
        using (Mp3FileReader mp3 = new Mp3FileReader(_inPath_))
        {
            using (WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(mp3))
            {
                WaveFileWriter.CreateWaveFile(_outPath_, pcm);
            }
        }
    }

去那里.

这篇关于将mp3数据转换为wav数据C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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