ISpGrammarBuilder (SAPI 5.4)

Speech API 5.4
Microsoft Speech API 5.4


This interface details the SAPI context-free grammar (CFG) backend compiler. These methods can be used to programmatically construct and modify grammars.

When To Use

Applications should use the ISpGrammarBuilder interface to change and save dynamically loaded grammars (see ISpRecoGrammar) and to change and save previously compiled binary grammars (see ISpGramCompBackend).

Methods in Vtable Order

ISpGrammarBuilder MethodsDescription
ResetGrammarClears all grammar rules (un-defines them) and resets the grammar's language to NewLanguage.
GetRuleRetrieves a grammar rule's initial state information (and defines the rule if requested).
ClearRuleRemoves all of the grammar rule information except for the rule's initial state handle.
CreateNewStateCreates a new state in the same grammar rule as hState.
AddWordTransitionAdds a word or a sequence of words to the grammar.
AddRuleTransitionAdds a rule (reference) transition from one grammar rule to another.
AddResourceAdds a resource (name and string value) to the grammar rule specified in hRuleState.
CommitPerforms consistency checks of the grammar structure, creates the serialized format, saves the grammar structure, reloads the grammar structure to the stream provided by SetSaveObjects, or reloads it into the SR engine.
Additionally, a sample code is provided to demonstrate ISpGrammarBuilder.