Converting mp3 data to wav data C#

非 Y 不嫁゛ 提交于 2019-12-04 13:08:15

问题


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);
   }

回答1:


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);
            }
        }
    }

There you go.



来源:https://stackoverflow.com/questions/11446096/converting-mp3-data-to-wav-data-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!