This project has moved. For the latest updates, please go here.

Insert silence at start and add silence to end

Jan 28, 2011 at 6:31 PM

Hello everyone,

 

I am new to NAudio, so this can be a very basic question or many of you.

 

I have a wav file and need to add n milliseconds of silence to the start and to add n milliseconds of silence to the end. How to proceed ?

 

 

Thanks in advance

Alfonso Moreno

Coordinator
Feb 1, 2011 at 10:06 AM

make a new WaveStream derived class that in the Read method returns the right amount of silence at the end and beginning of the source stream.

Mark

Feb 3, 2011 at 7:41 PM

Thank you very much.

 

Your suggestion took me to research a bit more then I found that the WaveOffsetStream is what I needed. I was surprised for the versatility of NAudio library.

 

Regards

Alfonso Moreno

Apr 22, 2015 at 5:45 AM
Hi everyone, i wrote this funcions to do this.
    private void InsertSilence(WaveFileWriter writer, Double milliseconds)
    {

        Double avgBytesPerMillisecond = (Double)writer.WaveFormat.AverageBytesPerSecond / 1000F;

        Int32 silenceSize = (Int32)(milliseconds * avgBytesPerMillisecond);
        silenceSize = silenceSize - silenceSize % fileIn.WaveFormat.BlockAlign;

        Byte[] silenceArray = new Byte[silenceSize];
        writer.Write(silenceArray, 0, silenceArray.Length);

    }