I use this function to join two wav files
public static void Concatenate(string outputFile, ArrayList sourceFiles)
{
byte[] buffer = new byte[1024];
WaveFileWriter waveFileWriter = null;
try
{
foreach (string sourceFile in sourceFiles)
{
using (WaveFileReader reader = new WaveFileReader(sourceFile))
{
if (waveFileWriter == null)
{
// first time in create new Writer
waveFileWriter = new WaveFileWriter(outputFile, reader.WaveFormat);
}
else
{
if (!reader.WaveFormat.Equals(waveFileWriter.WaveFormat))
{
//throw new InvalidOperationException("Can't concatenate WAV Files that don't share the same format");
}
}
int read;
while ((read = reader.Read(buffer, 0, buffer.Length)) > 0)
{
waveFileWriter.WriteData(buffer, 0, read);
}
}
}
}
catch (Exception ex)
{
}
finally
{
if (waveFileWriter != null)
{
waveFileWriter.Dispose();
}
}
}
But this function join the second wav file after the first wav's end.
What I really want is to join the second wav file 2 milliseconds before the wav's end .

Is there any way to do it using NAudio , or using some other library ?
What you are trying to do, is not a simple join of waves, is a merge. In a merge the waves will be combined to form one "mixed" wave.
To merge files you can follow this documentation of NAudio.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With