如何单词添加到使用System.Speech和SAPI 5.3已加载的语法 [英] How to add words to an already loaded grammar using System.Speech and SAPI 5.3

查看:262
本文介绍了如何单词添加到使用System.Speech和SAPI 5.3已加载的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于以下code,

Choices choices = new Choices();
choices.Add(new GrammarBuilder(new SemanticResultValue("product", "<product/>")));

GrammarBuilder builder = new GrammarBuilder();
builder.Append(new SemanticResultKey("options", choices.ToGrammarBuilder()));

Grammar grammar = new Grammar(builder) { Name = Constants.GrammarNameLanguage};
grammar.Priority = priority;

_recognition.LoadGrammar(grammar);

我如何添加额外的字来加载的语法?我知道这既可以在本地code和使用SpeechLib互操作来实现,但我preFER使用托管库。

How can I add additional words to the loaded grammar? I know this can be achieved both in native code and using the SpeechLib interop, but I prefer to use the managed library.

更新:我想实现什么,是不是有重复加载,因为个别的变化的整个语法。对于小的语法我得到了很好的效果,通过调用

Update: What I want to achieve, is not having to load an entire grammar repeatedly because of individual changes. For small grammars I got good results by calling

_recognition.RequestRecognizerUpdate()

,然后做事件旧语法重建的语法和加载卸载:

and then doing the unload of the old grammar and loading of a rebuilt grammar in the event:

void Recognition_RecognizerUpdateReached(object sender, RecognizerUpdateReachedEventArgs e)

有关大型语法这将成为太昂贵了。

For large grammars this becomes too expensive.

推荐答案

在本地SAPI,我会使用ISpGrammarBuilder2 :: AddTextSubset()。

In native SAPI, I'd use ISpGrammarBuilder2::AddTextSubset().

这篇关于如何单词添加到使用System.Speech和SAPI 5.3已加载的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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