Archiving and Releasing a Grammar

When an application is shutting down or is finished using a grammar, the application must release the grammar object (along with the engine object and all results objects) in order for the engine to free itself. The application releases a grammar object using the standard OLE COM mechanism of releasing all of the interfaces to the object.

Before the application releases a grammar object, however, it should call the ISRGramCommon::Archive member function. This copies the following information into memory:

· The internal representation of the grammar format. This allows the ISRCentral::GrammarLoad member function to proceed much faster the next time the grammar is used.

· Information about how the speaker uses the grammar. This might be the frequency of specific paths or words being used. Often this information is user-specific. This information improves recognition accuracy and speed the next time that the grammar is used.

· Results objects. The application can specify that data stored in all of the results objects be archived and retrieved the next time that the grammar is loaded.

The application can store the archive information anywhere, such as in a document file. The next time the application needs to use the grammar, it loads the information from the file into memory and calls the ISRCentral::GrammarLoad member function with the format SRGRMFMT_CFGNATIVE rather than SRGRMFMT_CFG (because the archived grammar is in the engine's native format). The grammar loads more quickly, and any information that the engine learned about the grammar in the last session is retained. Note that the new data format is engine-specific, so the application should maintain the grammar in standard CFG format in case the user changes speech-recognition engines in the application.

If the application archived results objects along with the grammar, the ISRGramNotifySink::UnArchive member function is called for each results object that was archived. This gives the application a chance to instantiate the archived data back into results objects and continue using them in the same state they were in before the Archive member function was called.