How to playback webcam audio

Dec 10, 2012 at 9:32 AM

Hello everyone,

I am a new user of NAudio and I am trying to capture audio from my webcam using WaveIn and is working fine. But I am not getting how to achieve simultaneous playback of this captured audio.

Could you please help me to do this? What interface should I use here?

Thanks.

Dec 10, 2012 at 9:45 AM

Hey guys I got the answer. We just need to use WaveOut object with the help of WaveInProvider! It was very simple... :-)

Dec 10, 2012 at 10:54 AM

Hello guys,

Now there is one more issue. I wanted to enable/disable audio playback at run time but without stopping the audio capture. I am stopping the playback using WaveOut.Stop() method but after few seconds my application is throwing InvalidOperationException (with message Buffer full). I went through the code and I observed that there is no way to stop the working of WaveInProvider; it go on adding captured audio samples to the BufferedWaveProvider because WaveIn is still capturing audio samples. And once buffer is full then BufferedWaveProvider throws InvalidOperationException.

Will you please suggest some possible solution for solving this issue?

I was thinking of adding Start and Stop methods to the IWaveProvider interface. Will it be fine?

Coordinator
Dec 10, 2012 at 1:22 PM

Well you can either stop putting audio into your buffer while you are stopped, or simply set your BufferedWaveProvider up to discard on overflow (set the DiscardOnBufferOverflow property to true).

Dec 10, 2012 at 2:04 PM

Hello sir,

Thanks for your reply. But I am not able to follow any of these two solutions because WaveInProvider don't provide any method to stop putting audio into the buffer while playback is stopped and DiscardOnBufferOverflow property is defined in BufferedWaveProvider whose object is private in WaveInProvider so I cannot use this object from my code.

Coordinator
Dec 10, 2012 at 2:18 PM

Don't use WaveInProvider then. It's a very simple class that uses WaveIn and BufferedWaveProvider.

Dec 11, 2012 at 4:42 AM

I am directly using BufferedWaveProvider and its working now. Thank you.