How to add words to an already loaded grammar using System.Speech and SAPI 5.3
Posted
by Kim Major
on Stack Overflow
See other posts from Stack Overflow
or by Kim Major
Published on 2008-11-29T16:32:04Z
Indexed on
2010/05/18
16:30 UTC
Read the original article
Hit count: 423
Given the following 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);
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.
© Stack Overflow or respective owner