Grammar Object Creation

After the application loads the grammar description into memory (or into a memory-mapped file), it loads the grammar by using the ISRCentral::GrammarLoad member function. When calling GrammarLoad, the application indicates the type of the grammar (context-free, dictation, or limited-domain) and its format (standard or engine-native). The application also specifies an SDATA structure that contains the address of the beginning of the grammar memory, and a value that indicates the number of bytes in the grammar data.

Optionally, an application can specify the address of an ISRGramNotifySink interface that the grammar object uses to notify the application of recognition events, and to pass information about the event to the application. To receive recognition notifications, an application must create a COM object that supports the ISRGramNotifySink interface. When a recognition event occurs, the grammar object notifies the application by calling the appropriate member function of the ISRGramNotifySink interface. You determine how the application responds to notifications. For more information about the ISRGramNotifySink interface, see "Grammar-Specific Notifications" later in this section.

When the application calls the GrammarLoad member function, the engine compiles the binary format into an internal format that the engine understands. Compiling the grammar may take some time, perhaps several seconds. If the grammar uses any features that the mode cannot support, such as links and lists, the GrammarLoad member function returns an error.

After the engine compiles the grammar into its own format, it creates a grammar object used to control the grammar. The grammar object supports several interfaces, including IUnknown and ISRGramCommon. Grammar objects attached to context-free grammars also support the ISRGramCFG interface.

If the grammar cannot be loaded because it is too complex or too large, or if it requires features not supported by the engine, the GrammarLoad member function returns an error. If the function succeeds, the fifth parameter receives the address of an IUnknown interface on the grammar object. An application can use the IUnknown interface to retrieve addresses of other interfaces supported by the grammar object.