语音识别引擎未在 Windows 服务中触发事件 [英] Speech Recognition Engine Not Firing Event in Windows Service

查看:37
本文介绍了语音识别引擎未在 Windows 服务中触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个使用 system.speech 识别引擎实现语音识别的 Windows 服务.当我启动服务时,我的语音识别代码运行良好,但没有语音识别火灾事件.奇怪的是,如果我运行完全相同的代码,但在控制台或 WPF 应用程序中运行,则语音识别的事件触发工作正常.
我已经在我的服务进程中附加了一个调试器来检查幕后发生了什么.语音识别引擎似乎正确加载语法,将其模式设置为连续收听,并正确设置语音识别事件.没有抛出异常,所以我不太确定这里出了什么问题.有什么想法吗?

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?

推荐答案

您是在使用麦克风还是在处理 WAV 文件?如果您尝试使用默认音频设备,我不确定音频管道将如何在服务中工作.如果您尝试从音频文件或流进行转换,请确保您使用的是 InProc 识别器.

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.

如果您正在创建服务器应用程序,您可能应该考虑使用 Microsoft.Speech API 和服务器识别器.请参阅 System.Speech.Recognition 和 Microsoft.Speech.Recognition? 以及 Microsoft Speech Platform SDK - http://www.microsoft.com/en-us/download/details.aspx?id=27226

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

如果您正在尝试在没有前台应用的情况下进行连续识别,我相信共享识别器可能能够满足您的需求.Windows 7 和 Vista 中附带的 Microsoft 桌面识别器可以在两种模式下工作:inproc 或共享.共享识别器在桌面上很有用,其中语音命令用于控制任何打开的应用程序.在 System.Speech 中,您可以使用 SpeechRecognizer访问共享桌面识别器或 SpeechRecognitionEngine为您的应用程序提供专用的 inproc 识别器.即使您的应用不在前台,您也可以使用共享识别器为您的应用提供持续识别.

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.

几年前在 http 上发表了一篇很好的文章://msdn.microsoft.com/en-us/magazine/cc163663.aspx.这可能是迄今为止我找到的最好的介绍性文章.它说:

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:

...识别引擎可以在另一个名为的进程中实例化SAPISVR.EXE.这提供了一个共享的识别引擎,可以由多个应用程序同时使用.这个设计有一个编号的好处.首先,识别器通常需要更多运行时资源比合成器多,并且共享识别器是一种减少开销的有效方法.其次,共享识别器是也由 Windows Vista 的内置语音功能使用.因此,使用共享识别器的应用程序可以从系统的麦克风和反馈 UI.没有额外的代码编写,并且没有供用户学习的新 UI.SAPI 5.3 的新功能

...recognition engine can be instantiated in another process called SAPISVR.EXE. This provides a shared recognition engine that can be used simultaneously by multiple applications. This design has a number of benefits. First, recognizers generally require considerably more run-time resources than synthesizers, and sharing a recognizer is an effective way to reduce the overhead. Second, the shared recognizer is also used by the built-in speech functionality of Windows Vista. Therefore, apps that use the shared recognizer can benefit from the system's microphone and feedback UI. There's no additional code to write, and no new UI for the user to learn.New to SAPI 5.3

这篇关于语音识别引擎未在 Windows 服务中触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆