views:

43

answers:

1

I'm using System.Speech.Recognition in Windows 7 to let the user control a program by voice commands. The recognition code is integrated into the program itself. Now, the recognition engine is created at program startup and recreated if the user changes the voice recognition language. This all works fine.

Recently we had an issue with the creation of the recognition engine. If the system default audio input changes during program run we have no way of responding to it. Specifically, if the mike was unplugged when the program started the recognition engine would not be able to find an input. I goes into a disabled state. If later the mike is plugged in I would like the program to notice this and update the engine.

Is there an exposed event for when the system default audio input changes?

+1  A: 

You need to implement IMMNotificationClient, and call IMMDeviceEnumerator::RegisterEndpointNotificationCallback. The NAudio guys have a C# wrapper for this; I'd look at it.

Eric Brown
Thanks! I had to dig through the source a bit before I found the wrapper. The documentation is sparse. From what I gather I need to implement an IMMNotificationClient and register it through a MMDeviceEnumeratorComObject instance. Haven't been able to try it yet though.
Staffan E