I have raw-headerless wav audio data as MemoryStream
s.
Stream rawAudioStream = Producer.GetRawAudioFileStream(...);
I know those streams data format:
// WaveFormat(int rate, int bits, int channels);
WaveFormat waveformat = new WaveFormat(8000, 16, 1);
What I want is to add programmatically right header info for those memory streams without writing them to a physical file.
How can I do that?
PS: I checked the NAudio Library but only found a way to create a header by writing streams to really-physical files which is not suitable for my situation.
var waveformat = new WaveFormat(8000,16,1);
var reader = new RawSourceWaveStream(rawAudioMemStream, waveformat);
using (var convertedStream = WaveFormatConversionStream.CreatePcmStream(reader))
{
WaveFileWriter.CreateWaveFile(fileName, convertedStream);
}
rawAudioMemStream.Close();
The below code will write a Wav header to the beginning of a
MemoryStream
. Which means you'll need to write the header to your stream first, and then you can write your samples. Otherwise the samples at the start of your stream will get overwritten with meta data,