The quick and dirty solution would be to iterate the array in reverse, writing each intermediate step to a temporary file:
string tempPath = GetTempPath();
string tempInputFile = Path.Combine(tempPath, Guid.NewGuid().ToString("N") + ".wav");
string tempOutputFile = Path.Combine(tempPath, Guid.NewGuid().ToString("N") + ".wav");
File.Copy(input, tempInputFile);
for (int i = array.Length - 2; i >= 0; i -= 2)
{
TrimWavFile(tempInputFile, tempOutputFile, TimeSpan.FromSeconds(array[i]), TimeSpan.FromSeconds(array[i + 1]);
File.Delete(tempInputFile);
File.Move(tempOutputFile, tempInputFile);
}
File.Delete(output);
File.Move(tempInputFile, output);
A better solution would be to change your
TrimWavFile
function so that it could remove more than one segment without having to load and save the file each time.