I'm using an NAudio wrapper for LAME to convert my wav file to mp3. However, when I use NAudio to convert my mp3 back to wav, the wav file is a bit larger than the original wav file. Is there a way I can get it so that the original and decoded wav files are exactly the same size? Aside from this everything else works and I'm able to play the wav and mp3 files without issue. Thanks and I have included my conversion functions below:
private void ConvertWavMP3(string wavFile)
{
try
{
using (var wavRdr = new WaveFileReader(wavFile))
using (var mp3Writer = new LameMP3FileWriter(wavFile.Replace(".wav", ".mp3"), wavRdr.WaveFormat, 128))
{
wavRdr.CopyTo(mp3Writer);
}
}
catch (Exception ex)
{
MessageBox.Show("Error converting wav to mp3.", "CONVERSION ERROR");
}
}
private static void ConvertMp3ToWav(string mp3File)
{
try
{
using (Mp3FileReader reader = new Mp3FileReader(mp3File))
{
//using (WaveStream pcmStream = new WaveFormatConversionStream(new WaveFormat(8000, 16, 1), reader))
using (WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader))
{
WaveFileWriter.CreateWaveFile(mp3File.Replace(".mp3", ".wav"), pcmStream);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error converting mp3 to wav.", "CONVERSION ERROR");
}
}