Convert mp4 voice file to WAV stream

855 Views Asked by At

I used this code to resample file and save it but the file sounds like fast-forward recording:

using (MediaFoundationReader reader = new MediaFoundationReader(url))
{
    using (ResamplerDmoStream resampledReader = new ResamplerDmoStream(reader, new WaveFormat(16000, 16, 1)))
        {
            using (WaveFileWriter waveWriter = new WaveFileWriter(@"c:\test.wav", resampledReader.WaveFormat))
                {
                    resampledReader.CopyTo(waveWriter);
                }
         }
}
2

There are 2 best solutions below

3
On

The WaveFileWriter must have the same WaveFormat as resampledReader. So pass in resampledReader.WaveFormat to the WaveFileWriter constructor.

0
On

I'm not sure what resampling means, but if you need to get the wav from a video, this works...

using (var video = new MediaFoundationReader(file))
{
    file = TempWav;
    WaveFileWriter.CreateWaveFile(file, video);
}