Compiling Grammars

When your speech application first begins the process of decoding audio, it sends a grammar with the audio to the Speech Engine. In order for the Engine to read the grammar, the grammar has to be compiled into a binary format that the Engine can read.

It used to be that the Engine had to load and compile its grammars each time that a grammar was used, which was time consuming and used up significant resources in the process. Grammars with thousands of words can take several seconds to compile.

If you are using a large grammar, you probably do not want to wait several seconds to load it every time your application needs to use it. This is especially true for telephony applications, where you cannot have a caller waiting while the Engine compiles a grammar.

In Speech Engine version 8.0 and later, the Engine has incorporated a feature which keeps compiled grammars in its cache automatically, allowing you to use large grammars without having to wait for them to be compiled after the very first time a grammar is loaded.

Grammars, once loaded, do not need to be compiled again if no changes have been made to them.

Understanding this process is made easier if you understand the distinction between the LumenVox client and server. The client is the application which uses our SpeechPort library — it may be a custom application you have built using our API, our own MRCP server, or a voice platform that has done an API-level integration of LumenVox.

The client loads grammars and audio and sends them in a packet to the speech server, which is the process that uses the grammar and audio to perform decodes. It is the server that needs the compiled grammar.

Because clients and servers may reside on different machines using different environments and architectures, the speech server performing the decode must compile the grammar. A binary grammar file compiled on a Sun SPARC machine running Solaris will not work with one compiled on an Intel machine running Windows.

Before the server compiles the grammar, it takes a hash of the grammar(a hash is a way to quickly create a unique identifier for a file, and if the contents of a file change even slightly so does the hash).

The server saves the hash and compiles the grammar, writing a copy of the compiled grammar to disk.

The next time a grammar is passed to the server, the server takes a hash of the grammar and checks to see if it already has a compiled version of it in cache. If so, it uses the precompiled one, and saves itself the resources and time of compilation.

If the hashes don't match, then there has been a change to the grammar, and the Engine compiles the new one.

All of this means that there will only be a delay the first time a grammar is loaded. After that, grammar caching ensures the Engine does not recompile the same grammar.

The only manual effort needed is if you are using the Speech Engine on more than one machine. If this is the case, you can load the grammar on one server, and then manually copy the compiled grammar from the cache directory on that server into the cache directories on the other machines.

The cache directory defaults to the following locations:

For Windows, version 8.6: C:\Program Files\Lumenvox\Engine\Lang\cached_grammars

For Linux, version 8.6: /var/lumenvox/cached_grammars/

Please note that this will most likely not work if the secondary Engines are running on a different OS/distribution than the source Engine.

© 2010 LumenVox LLC. All rights reserved.