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?
Adding Beep or Silence for a given duration in an Audio file || NAudio || C#
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);
}
}
© 2022 - 2024 — McMap. All rights reserved.