How to convert a 16 bit PCM: 44kHz 2 channels with a sample rate of 44100 to a mp3 file

778 views Asked by At

I need to convert a 16 bit PCM: 44kHz 2 channels wave file to mp3 format.

I'm converting this to compress the size of the wave file.

I tried using NAudio.Lame

public static byte[] ConvertWavToMp3(byte[] wavFile)
    {

       using (var retMs = new MemoryStream())
       using (var ms = new MemoryStream(wavFile))
       using (var rdr = new WaveFileReader(ms))
       using (var wtr = new LameMP3FileWriter(retMs, rdr.WaveFormat, 128))
       {
           rdr.CopyTo(wtr);
           return retMs.ToArray();
       }

But this throws an error:

NAudio.Wave.WaveFileReader' does not contain a definition for 'CopyTo' and no extension method 'CopyTo' accepting a first argument of type 'NAudio.Wave.WaveFileReader' could be found

I throws another error:

Error 3 The type or namespace name 'Lame' does not exist in the namespace 'NAudio' (are you missing an assembly reference?)

Please help me out.

0

There are 0 answers