为什么当我在windows7系统中使用SpeechLib.SpSharedRecoContext时,会自动打开系统自带的语音识别工具?以下是我的代码,当它在windows7系统中运行语音识别工具时会打开,我必须单击系统工具的begin按钮,然后我的程序才能开始识别。
private const int grammarId = 10;
private bool speechInitialized = false;
private SpeechLib.SpSharedRecoContext objRecoContext;
private SpeechLib.ISpeechRecoGrammar grammar;
private SpeechLib.ISpeechGrammarRule ruleListItems;
private void InitializeSpeech(List<string> userKeyWords = null, bool isUseSystemGrammar = false)
{
try
{
// First of all, let's create the main reco context object.
// In this sample, we are using shared reco context. Inproc reco
// context is also available. Please see the document to decide
// which is best for your application.
objRecoContext = new SpeechLib.SpSharedRecoContext();
// Then, let's set up the event handler. We only care about
// Hypothesis and Recognition events in this sample.
objRecoContext.Hypothesis += new
_ISpeechRecoContextEvents_HypothesisEventHandler(
RecoContext_Hypothesis);
objRecoContext.Recognition += new
_ISpeechRecoContextEvents_RecognitionEventHandler(
RecoContext_Recognition);
objRecoContext.AudioLevel += new _ISpeechRecoContextEvents_AudioLevelEventHandler(objRecoContext_AudioLevel);
objRecoContext.EventInterests = SpeechRecoEvents.SREAllEvents;
// Now let's build the grammar.
grammar = objRecoContext.CreateGrammar(grammarId);
ruleListItems = grammar.Rules.Add("ListItemsRule",
SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
RebuildGrammar(userKeyWords, isUseSystemGrammar);
// Now we can activate the top level rule. In this sample, only
// the top level rule needs to activated. The ListItemsRule is
// referenced by the top level rule.
grammar.CmdSetRuleState("ListItemsRule", SpeechRuleState.SGDSActive);
speechInitialized = true;
}
catch (Exception e)
{
Loger.LogErr(e);
}
}如何防止我的程序依赖于系统工具?谢谢。
顺便说一下,在windows xp系统中,这不是一种现象。
发布于 2013-11-23 02:27:38
在Windows Vista及以上版本中,创建共享识别器(SpeechLib.SpSharedRecoContext)将自动启动Windows Speech Recognition,这是共享识别器的通用UI。
如果您不想这样做,您可以创建进程内识别器(SpeechLib.SpInProcRecoContext) -但是,如果这样做,您需要显式管理音频源、识别引擎和用户配置文件:
private SpeechLib.SpInprocRecoContext CreateInprocRecoContext()
{
SpeechLib.SpObjectTokenCategory Category = new Speechlib.SpObjectTokenCategory();
Category.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryAudioIn);
SpeechLib.SpObjectToken AudioToken = new SpeechLib.SpObjectToken();
AudioToken.SetId(Category.Default());
Category.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryRecognizers);
SpeechLib.SpObjectToken EngineToken = new SpeechLib.SpObjectToken();
EngineToken.SetId(Category.Default());
Category.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryRecoProfiles);
SpeechLib.SpObjectToken ProfileToken = new SpeechLib.SpObjectToken();
ProfileToken.SetId(Category.Default());
SpeechLib.SpInprocRecognizer reco = new SpeechLib.SpInprocRecognizer();
reco.SetRecognizer(EngineToken);
reco.SetInput(AudioToken);
reco.SetRecoProfile(ProfileToken);
return reco.CreateRecoContext();
}https://stackoverflow.com/questions/20125238
复制相似问题