Note
Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.
Microsoft Speech Platform
Load and Activate Grammars
After you have created a speech recognition grammar, your application must load it to an SpRecoGrammar object and activate the rules in the grammar before it can be used to perform recognition. You can load a grammar using one of the LoadCmdXXX methods of ISpRecoGrammar. The speech recognition engine must be stopped or paused to load a grammar. You can use ISpRecoContext::Pause to pause a running recognition engine to load a grammar.
Example
The following code snippet creates a grammar object and loads a file that contains an XML-format grammar that conforms to the Speech Recognition Grammar Specification (SRGS) Version 1.0. The example sets the state of the grammar to active. `
// Create a new grammar and load an SRGS grammar from a file. CComPtr<ISpRecoContext> cpContext; CComPtr<ISpRecoGrammar> cpGrammar;`if (SUCCEEDED(hr)) { hr = cpContext->CreateGrammar(0, &cpGrammar;); }
if (SUCCEEDED(hr)) { hr = cpGrammar->LoadCmdFromFile(L"TestGrammar.grxml", SPLO_STATIC); }
// Activate the grammar. if (SUCCEEDED(hr)) { hr = cpGrammar->SetGrammarState(SPGS_ENABLED); }
if (SUCCEEDED(hr)) { // Create and configure a recognizer to begin recognition. }