5

I am using NAudio to record and play the audio file. Now, I want to add silence or beep in an audio file for a given duration. Could you please suggest the NAudio provider name in order to achieve it?

Arindam Rudra
  • 604
  • 2
  • 9
  • 24

1 Answers1

9

To generate a beep, take a look at SignalGenerator, which can generate a sine wave. There is a Take extension method to limit the duration of the beep. For silence, you can use the same technique, except with SilenceProvider.

Here's a simple example of two beeps with silence between them:

var beep1 = (new SignalGenerator(){ Frequency = 1000, Gain = 0.2}).Take(TimeSpan.FromSeconds(2));
var silence = new SilenceProvider(beep1.WaveFormat).ToSampleProvider().Take(TimeSpan.FromSeconds(2));
var beep2 = (new SignalGenerator() { Frequency = 1500, Gain = 0.2 }).Take(TimeSpan.FromSeconds(2));
var concat = beep1.FollowedBy(silence).FollowedBy(beep2);
using (var wo = new WaveOutEvent())
{
    wo.Init(concat);
    wo.Play();
    while(wo.PlaybackState == PlaybackState.Playing)
    {
        Thread.Sleep(500);
    }
}
Mark Heath
  • 48,273
  • 29
  • 137
  • 194