首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么当我在windows7系统中使用SpeechLib.SpSharedRecoContext时,会自动打开系统自带的语音识别工具?

为什么当我在windows7系统中使用SpeechLib.SpSharedRecoContext时,会自动打开系统自带的语音识别工具?
EN

Stack Overflow用户
提问于 2013-11-21 23:38:03
回答 1查看 1K关注 0票数 0

为什么当我在windows7系统中使用SpeechLib.SpSharedRecoContext时,会自动打开系统自带的语音识别工具?以下是我的代码,当它在windows7系统中运行语音识别工具时会打开,我必须单击系统工具的begin按钮,然后我的程序才能开始识别。

代码语言:javascript
复制
 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系统中,这不是一种现象。

EN

回答 1

Stack Overflow用户

发布于 2013-11-23 02:27:38

在Windows Vista及以上版本中,创建共享识别器(SpeechLib.SpSharedRecoContext)将自动启动Windows Speech Recognition,这是共享识别器的通用UI。

如果您不想这样做,您可以创建进程内识别器(SpeechLib.SpInProcRecoContext) -但是,如果这样做,您需要显式管理音频源、识别引擎和用户配置文件:

代码语言:javascript
复制
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();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20125238

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档