CSCore - Play audio from a MemoryStream

I am new to CsCore. Help is needed. I want to create an Audio Recorder that is capable of recording microphone and speakers to file and external Recorder. I have successfully finished writing to the file. Now I want to do the same thing again but play on a specific audio device. I thought about putting a pipeline into a stream and using that stream as the source for WasapiOut. However, I was unable to connect this stream to the IWaveSource.

private Stream _strm;
private WaveWriter _waveWriterFile;
private WaveWriter _wavewriterStream;
private WasapiOut _externalRecorder;

_strm = new MemoryStream();
_wavewriterStream = new WaveWriter(_strm, _SpkCapture.WaveFormat);
IWaveSource ws = new WaveFileReader(_strm);
_externalRecorder.Initialize(ws);
_externalRecorder.Play();

// on Event I do following:
_waveWriterFile.Write(e.Data, e.Offset, e.ByteCount);
_wavewriterStream.Write(e.Data, e.Offset, e.ByteCount);

      

Everything works fine until I call 'new WaveFileReader (_strm);'. I am getting an exception (translation from me) "cannot read outside of stream". The stream contains data at this point in time. Allow 100ms to sleep before trying to fetch the stream. I have also tried

IWaveSource ws = new CSCore.MediaFoundation.MediaFoundationDecoder(strm); 

      

But no luck. I really need help.

+3


source to share





All Articles