0

I need to concatenate two wav audio files with 30 seconds of whute sound between them.

I want to use the NAudio library - or with any other way that work.

How to do it ?

( the different from any other question is that i need not only to make one audio file from two different audio files .. i also need to add silent between them )

Yanshof
  • 9,659
  • 21
  • 95
  • 195
  • Possible duplicate of [How to join 2 or more .WAV files together programmatically?](https://stackoverflow.com/questions/6777340/how-to-join-2-or-more-wav-files-together-programmatically) – galoget Jan 25 '18 at 08:31
  • @galoget i saw this example - but this is not with 30 seconds between the two files – Yanshof Jan 25 '18 at 08:35
  • Try with this one: [Concatenate wave files at 5 second intervals with NAudio](https://stackoverflow.com/questions/8017480/concatenate-wave-files-at-5-second-intervals) or use `sox`, here is how: [combine multiple audio files with silence between each audio file in sox](https://askubuntu.com/questions/631771/combine-multiple-audio-files-with-slience-between-each-audio-file-in-sox) – galoget Jan 25 '18 at 08:39

1 Answers1

2

Assuming your WAV files have the same sample rate and channel count, you can concatenate using FollowedBy and use SignalGenerator combined with Take to get the white noise.

var f1 = new AudioFileReader("ex1.wav");
var f2 = new SignalGenerator(f1.WaveFormat.SampleRate, f1.WaveFormat.Channels) { Type = SignalGeneratorType.White, Gain = 0.2f }.Take(TimeSpan.FromSeconds(5));
var f3 = new AudioFileReader("ex3.wav");
using (var wo = new WaveOutEvent())
{
    wo.Init(f1.FollowedBy(f2).FollowedBy(f3));
    wo.Play();
    while (wo.PlaybackState == PlaybackState.Playing) Thread.Sleep(500);
}
Mark Heath
  • 48,273
  • 29
  • 137
  • 194