Precompiled grammars

The CPQD ASR allows grammars to be compiled before being loaded for recognition. A precompiled grammar takes less time to be loaded into the recognition engine, and can take less time to recognize speech, but this is not guaranteed.

Precompiled grammars are recommended for cases in which the grammar to be used is too large and takes a longer time to be compiled than the application developer considers ideal.

The tool used to compile grammars is ``grammar-compile`. As an example, let’s compile the pizza.gram grammar from the previous section. This can be done using the following command:

$ grammar-compile pizza.gram

This command creates the local directory pizza, and places all the files of the compiled grammar there. The output directory can be edited using the --out option.

Warning

When using the above command, the grammar will be compiled with the installed default language package. If you have installed the Spanish acoustic model as the default language, the grammar will be compiled for this language, even if the Portuguese model is also installed on the machine. Follow the steps below to define the compilation language.

Compiling to another language

If you wish to compile a grammar to a different language than the default language installed on the system, you can define this using the grammar-compile command.

To verify what language packages are installed on the system, run cpqdasr-info:

$ cpqdasr-info

=== CPqD ASR information ===

Collected: 2018-12-01T13:24:56+0000

--- Machine information ---

Linux: CentOS Linux release 7.6.1810 (Core)
Hostname: fe6fbe2b9b5f
MemTotal:       16329200 kB
MemAvailable:    6513268 kB
CPU(s):                4
Socket(s):             1
Model name:            Intel(R) Core(TM) i7-4600U CPU @ 2.90GHz
Disk space [/opt/cpqd/asr]: 61G
Disk space [/var/log/cpqd/asr]: 61G
Java installed: Java(TM) SE Runtime Environment (build 1.8.0_131-b11)

--- ASR packages installed ---

am-es-8k-1.0.6-b2
am-ptbr-8k-1.0.6-b4
cpqd-asr-engine-RHEL7.2-3.3.0-m
cpqd-asr-server-java1.8-3.7.0
grammar-es-builtin-1.0.1
grammar-ptbr-builtin-1.0.2
slm-es-1.0.0-am-es-8k-1.0.6-b2
slm-ptbr-1.0.0-am-ptbr-8k-1.0.6-b2

--- ASR configuration ---

Language package: es-8k-1.0.6
Language: es
Audio sampling rate (Hz): 8k
SLM: builtin:slm/general
SLM installed: true
License type: server
License ID: ABCDABCD00000001
Channels: 10

In our example, the default acoustic model is Spanish (Language package: es-8k-1.0.6), but we want to use the Portuguese model. The release of the Portuguese package is “am-ptbr-8k-1.0.6-b4” (see the ASR packages installed section ), but to compile this grammar we need to enter the name of the language package ‘ptbr-8k-1.0.6’. To do that, run grammar-compile with the --am parameter, as shown in the following example:

$ grammar-compile --am=ptbr-8k-1.0.6 pizza.gram

A local directory pizza will be created, with the grammar compiled for Brazilian Portuguese, using the language package ptbr-8k-1.0.6.

Compiling XML grammars

The grammar-compile tool also accepts grammars in XML format. Compiling XML grammars is accomplished exactly the same way as compiling ABNF grammars:

$ grammar-compile pizza.grxml

The compiled grammar will also be stored in the newly-created pizza directory.

To use a precompiled grammar for speech recognition, simply indicate the grammar directory path, generated by the grammar-compile tool.

Precompiled grammars take less time to load than other grammars.