How can I play byte array of audio raw data using NAudio?

Eido95 picture Eido95 · Mar 1, 2015 · Viewed 12.7k times · Source
byte[] bytes = new byte[1024];

Assume bytes is an array filled with audio raw data.

How can I play this byte array using a WaveOut object?

_waveOut.Init(bytes); // <- Error: cannot resolve method.
_waveOut.Play();

Answer

Eido95 picture Eido95 · Mar 1, 2015

I figured it out, here is the solution:

byte[] bytes = new byte[1024];

IWaveProvider provider = new RawSourceWaveStream(
                         new MemoryStream(bytes), new WaveFormat());

_waveOut.Init(provider);
_waveOut.Play();