Speech recognition error does not start in Windows service

So, I have a speech recognition Windows service implemented using the system.speech recognition engine. My speech recognition code works fine when I start the service, but there are no events for speech recognition. The strange thing is, if I run the same code, but instead in a console or WPF application, triggering events for speech recognition works fine.
I already connected a debugger to my service to check what is going on behind the scenes. It seems that the speech recognition engine correctly loads the grammar, sets its mode for continuous listening and correctly configures the event recognized by the speech. No exceptions are thrown, so I'm not too sure what is wrong here. Any ideas?

+6
source share
3 answers

Do you use a microphone or process a WAV file? I'm not sure how sound plumbing will work in a service if you are trying to use the default sound device. If you are trying to convert from audio files or stream, make sure that you are using InProc recognizer.

If you are building a server application, you should probably consider using the Microsoft.Speech API and server recuperators. See What is the difference between System.Speech.Recognition and Microsoft.Speech.Recognition? and Microsoft Speech Platform SDKs - http://www.microsoft.com/en-us/download/details.aspx?id=27226

If you are trying to perform continuous recognition without your application in the foreground, I believe that a common recognizer can support your needs. Microsoft Desktop Recognition, which comes in Windows 7 and Vista, can work in two modes: inproc or shared. Common 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 public desktop recognizer or SpeechRecognitionEngine so that you have a dedicated inproc recognizer for your application. You may be able to use a common recognizer to continuously recognize your application, even if your application is not in the foreground.

There is a very good article published a few years ago at http://msdn.microsoft.com/en-us/magazine/cc163663.aspx . This is probably the best introductory article I've found so far. It says:

... a recognition engine can be created in another process called SAPISVR.EXE. This provides a common recognition engine that can be used simultaneously by multiple applications. This design has a number of advantages. First, recognizers typically require significantly more resources than synthesizers, and sharing a recognizer is an effective way to reduce overhead. Secondly, the common recognizer is also used by the built-in speech features of Windows Vista. Therefore, applications using a common recognizer can benefit from the system microphone and feedback interface. There is no additional code for writing, and there is no new user interface for the user. New to SAPI 5.3

+1
source

The SpeechRecognition function should run in a separate thread and come OOTB from SpeechRecognitionEngine, if something like this:

static ManualResetEvent _completed = null; static void Main(string[] args) { _completed = new ManualResetEvent(false); SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine(); _recognizer.RequestRecognizerUpdate(); // request for recognizer update _recognizer.LoadGrammar(new Grammar(new GrammarBuilder("test")) Name = { "testGrammar" }); // load a grammar _recognizer.RequestRecognizerUpdate(); // request for recognizer update _recognizer.LoadGrammar(new Grammar(new GrammarBuilder("exit")) Name = { "exitGrammar" }); // load a "exit" grammar _recognizer.SpeechRecognized += _recognizer_SpeechRecognized; _recognizer.SetInputToDefaultAudioDevice(); // set the input of the speech recognizer to the default audio device _recognizer.RecognizeAsync(RecognizeMode.Multiple); // recognize speech asynchronous _completed.WaitOne(); // wait until speech recognition is completed _recognizer.Dispose(); // dispose the speech recognition engine } void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { if (e.Result.Text == "test") // e.Result.Text contains the recognized text { Console.WriteLine("The test was successful!"); } else if (e.Result.Text == "exit") { _completed.Set(); } } 

I also had a problem when I used SpeechRecognition, not SpeechRecognitionEngine. above is a great use case + listening to events in another thread. ps: I got a link from a long article: Speech recognition, speech in text, text to speech and speech synthesis in C # Fun :)

+4
source

Did you try to configure the service to interact with the desktop?

Image

I believe this is interaction with a user interface, for example, with a microphone.

0
source

Source: https://habr.com/ru/post/914482/


All Articles