NAudio
NAudio copied to clipboard
Wrong length after converting mp3 to wav
Hi, i try convert mp3 file to wav and get wrong length. My code:
using var reader = new Mp3FileReader(filePath);
using var pcmStream = WaveFormatConversionStream.CreatePcmStream(reader);
WaveFileWriter.CreateWaveFile(outputfilePath, pcmStream);
For mono mp3 file with 8000 rate and 5.503s duration get wav file with 5.760s duration. For stereo mp3 file with 8000 rate and 60.947s duration get wav file wtih 61.200s duration. NAudio add 0.210s at begin and 0.047s at the end for each file. ffmpeg correct convert files
There is typically padding error at the start and end of MP3s because that is how they work. By the way, you don't need WaveFormatConversionStream at all - get rid of that and it might help a bit. Another option to try is to use MediaFoundationReader instead which uses Window Media Foundation. Alternatively just use FFMPEG for the conversion.