Attach two wav files in NAudio to the first end of wav

I use this function to combine 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 joins the second wav file after the first end of wav.

enter image description here

I really want to join the second wav file 2 milliseconds before the end of wav.

enter image description here

Is there a way to do this using NAudio or using some other library?

+5
source share
1 answer

What you are trying to do is not just a union of waves, it is a merger. In the merger, the waves will be combined into one "mixed" wave.

To combine files, you can follow this NAudio documentation .

+1
source

Source: https://habr.com/ru/post/1235754/


All Articles