public static byte[] ConvertMp3ToWav(byte[] mp3File) { using (var retMs = new MemoryStream()) using (var ms = new MemoryStream(mp3File)) using (Mp3FileReader reader = new Mp3FileReader(ms)) { var rs = new RawSourceWaveStream(reader, new WaveFormat(31000, 1)); using (WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(rs)) { WaveFileWriter.WriteWavFileToStream(retMs,pcmStream); 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)) // originally 128 (as in 128K, but value itself should be 128) using (var wtr = new LameMP3FileWriter(retMs, rdr.WaveFormat, 256)) { rdr.CopyTo(wtr); byte[] result = retMs.ToArray(); wtr.Flush(); return result; } }
public static byte[] ConvertWavToMp3(byte[] wavFile) { using(var retMs = new MemoryStream()) using (var ms = new MemoryStream(wavFile)) using(var rdr = new WaveFileReader(ms)) // originally 128 (as in 128K, but value itself should be 128) using (var wtr = new LameMP3FileWriter(retMs, rdr.WaveFormat, 256)) { rdr.CopyTo(wtr); byte[] result = retMs.ToArray(); return result; } }