looking for some solutions? You are welcome.

SOLVED: Is there a way to actually write a fade-out to a wav file using NAudio?

Ahmed Abdelhameed:

I'm using NAudio to convert & trim some audio files, and I'm trying to add a fade-out to the last few seconds of each file.

I have checked this question, this, and this, but all the answers are talking about playing the wav file with fade, while I need to actually write that fade to an output file.

So, is there any way to do this using NAudio? If not, I'm open to other suggestions.


Edit: This is what I've tried:

private void PerformFadeOut(string inputPath, string outputPath)
{
    WaveFileReader waveSource = new WaveFileReader(inputPath);

    ISampleProvider sampleSource = waveSource.ToSampleProvider();

    OffsetSampleProvider fadeOutSource = new OffsetSampleProvider(sampleSource);
    // Assume the length of the audio file is 122 seconds.
    fadeOutSource.SkipOver = TimeSpan.FromSeconds(120);   // Hard-coded values for brevity

    // Two seconds fade
    var fadeOut = new FadeInOutSampleProvider(fadeOutSource);
    fadeOut.BeginFadeOut(2000);

    Player = new WaveOut();

    Player.Init(fadeOut);
    Player.Play();    
}

When I play the audio after applying the fade using Player.Play() -as shown in the method above-, it works perfectly as expected, and I can hear the fade. Now, I would like to export this result to an output WAV file.

I tried doing that by adding the following line:

WaveFileWriter.CreateWaveFile(outputPath, waveSource);

However, the output file doesn't have any fade applied to it. So, what am I missing here?



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE
Share:

No comments:

Recent