3
votes

I have been using the code in http://opensebj.blogspot.com/2009/04/naudio-tutorial-5-recording-audio.html to record audio. Basically this code:

WaveIn waveInStream;
WaveFileWriter writer;

waveInStream = new WaveIn(44100,2);
writer = new WaveFileWriter(outputFilename, waveInStream.WaveFormat);

waveInStream.DataAvailable += new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);
waveInStream.StartRecording();

It works perfectly and record every sound on the system. The problem arises when I pluck in a headset (not usb, just directly into the headset jack on the built in soundcard on my laptop). This has the effect that any sound I can hear in the headset is not recorded. I think it has something to do with which device i am recording from, but I can't quite figure it out.

I am trying to record a conversation, which means I would like to record the sound that comes from the mic and the sound I can hear in the headset at the same time.

Can someone point me in the right direction for this? Thanks.

1

1 Answers

2
votes
// Get default capturer
waveInStream = new WaveIn(44100,2);

Now if you plug in your headset microphone/speaker then Windows will detect it but your program is still using the old 'default' endpoint. Not the lastly added device. This needs to be updated.

One of the solution would be to poll the endpoints and see if any new (default) device has been added to the system and then stop-start the recording with the new device.

waveInStream.StopRecording();
// assign the default recording device if not already done
//waveInStream.DeviceNumber = 0;
waveInStream.StartRecording();

Let me know if I was not very clear in the explanation.