1

I am trying to concatenate multiple audio files together using NAudio.

I have collection of byte arrays, where the byte arrays represent the individual audio tracks.

var samples = new List<ISampleProvider>();

  foreach (var item in collection) {
    ISampleProvider tempAudio = new RawSourceWaveStream(new MemoryStream(item), new WaveFormat()).ToSampleProvider();
    samples.Add(tempAudio);
  }

  var playlist = new ConcatenatingSampleProvider(samples);

  WaveFileWriter.CreateWaveFile("playlist.wav", playlist.ToWaveProvider());

However, the audio that is saved to the file "playlist.wav" does not sound like the audio before attempting to concatenate it. The audio sounds much faster and incoherent.

Callum Osborn
  • 321
  • 4
  • 13
  • Check out [this answer](https://stackoverflow.com/a/6778791/6923568). It doesn't use `ConcatenatingSampleProvider` but it should do the trick. – Mat Feb 25 '19 at 20:46

1 Answers1

0

What audio format are the "items" in collection? The WaveFormat you provide to RawSourceWaveStream must exactly match the audio in item. You're just creating a default WaveFormat which IIRC is going to be 44.1kHz 16 bit stereo

Mark Heath
  • 48,273
  • 29
  • 137
  • 194