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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.