So I have a windows service with speech recognition implemented using the system.speech recognition engine. My speech recognition code runs fine when I start the service but no events for speech recognized fires. The strange thing is, if I run the exact same code, but in a console or WPF app instead, the event firing for speech recognition works just fine.
I have already attached a debugger to my service process to check what was going on behind the scenes. It seems as though the speech recognition engine properly loads the grammars, sets its mode to listen continuously, and properly sets up the speech recognized event. No exceptions are thrown so I am not too sure what is wrong here. Any ideas?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Can we recover audio from MFCC coefficients?
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
Have you tried setting the service to be allowed to interact with the desktop?
I believe that interaction with user interfacing devices like a microphone is covered by this setting.
Are you using the microphone or processing a WAV file? I'm not sure how the audio plumbing will work in a service if you are trying to use the default audio device. If you are trying to convert from audio files or a stream, make sure you are using an InProc recognizer.
If you are creating a server app, you probably should consider using the Microsoft.Speech API and the server recongizers. See What is the difference between System.Speech.Recognition and Microsoft.Speech.Recognition? and the Microsoft Speech Platform SDK - http://www.microsoft.com/en-us/download/details.aspx?id=27226
If you are trying to do continuous recognition without your app in the foreground, I believe the shared recognizer may be able to support your need. The Microsoft desktop recognizer that ships in Windows 7 and Vista can work in two modes: inproc or shared. Shared recognizers are useful on the desktop where voice commands are used to control any open applications. In System.Speech you can use SpeechRecognizer to access the shared desktop recognizer or SpeechRecognitionEngine to have a dedicated inproc recognizer for your application. You might be able to use the shared recognizer to provide continuous recognition to your application even when your app is not in the foreground.
There is a very good article that was published a few years ago at http://msdn.microsoft.com/en-us/magazine/cc163663.aspx. It is probably the best introductory article I’ve found so far. It says:
The SpeechRecognition should be run on seperate thread and is coming OOTB from SpeechRecognitionEngine , should something like that:
Also had a problem similar when i used SpeechRecognition and not SpeechRecognitionEngine. the above is a great sample of the usage + its listenining to events in another thread. p.s: i got the reference from a great article: Speech recognition, speech to text, text to speech, and speech synthesis in C# have Fun :)