views:

260

answers:

2

Is there a way to programmatically detect whether the microphone is on on Windows?

+2  A: 

This is not tested in any way, but I would try to read some samples and see if there is any variation. If the mike is on then you should get different values from the ambient sounds. If the mike is off you should get a 0. Again this is just how I imagine things should work - I don't know if they actually work that way.

rslite
It sounds right. I think this is how it's done by Skype - based on the message displayed either if no mic is connected, or it is quiet for other reasons: "Your microphone is really quiet"
awe
+6  A: 

No, microphones don't tell you whether they're ‘on’ or that a particular sound channel is connected to a microphone device. The best you can do is to read audio data from the input channel you suspect to be a microphone (eg. the Windows default input device/channel), and see if there's any signal on it.

To do that you'd have to remove any DC offset and look for any signal above a reasonable noise floor. (Be generous: many cheap audio input devices are quite noisy even when there is no signal coming in. A mid-band filter/FFT would also be useful to detect only signals in the mid-range of a voice and not low-frequency hum and transient clicks.)

bobince