Reduce WAV file size using cscore library

371 Views Asked by At

I want to reduce WAV file using cscore libary without loosing audio, something like NAudio

var pcmStream = WaveFormatConversionStream.CreatePcmStream(inputSteam); var wavCompressedStream = new WaveFormatConversionStream(target, pcmStream);

1

There are 1 best solutions below

1
Florian On

You can change the format of a wave file with by opening the existing audio data as IWaveSource, changing its format and writing it back to any stream or file. For example:

IWaveSource waveSource = ...

waveSource
    .ToMono() //for example, convert to mono
    .ChangeSampleRate(44100) // specify samplerate
    .ToSampleSource()
    .ToWaveSource(16) //specify bits per sample
    .WriteToWavStream(stream);

But keep in mind that you probably will loose audio quality by downsampling, changing bits per sample, ...