molioron
molioron
CC#
Created by molioron on 7/16/2023 in #help
❔ 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();
}

}
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?
20 replies