C#C
C#3y ago
molioron

❔ Problem with converting WAV byte[] to MP3 byte[] (and vice versa)

I have this code (using NAudio) for converting a wav byte array to an mp3 byte array:
    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, 256))
        {
            rdr.CopyTo(wtr);
            return retMs.ToArray();
        }

    }

Not sure why, but using the function the end of a wav file just gets cut off (examples attached)
How can I fix this or are there any alternative ways of conversion?
Was this page helpful?