Skip to main content

How to Specify Grammar Files

When performing speech recognition using the "音声入力_ルール" engine (-a-rule-input-private), specify connection_engine_name|grammar_file in the "grammarFileNames" request parameter.

grammarFileNames=<connection_engine_name|grammar_file>

The detailed specification methods are explained below.

How to Specify the URL of a Grammar File

By placing a grammar file on a web server or similar and specifying its URL in grammarFileNames, you can use that grammar file for speech recognition.

grammarFileNames=<connection_engine_name|URL of grammar file>

For example, when using the Synchronous HTTP interface to use a grammar file whose URL is http://dummy.com/grammars/Sample.gram, grammarFileNames is specified in the d parameter, and since the parameter needs to be URL-encoded, it becomes as follows:

d=grammarFileNames=-a-rule-input-private%7Chttp%3A%2F%2Fdummy.com%2Fgrammars%2FSample.gram

How to Write a Grammar Directly in the Request

If you do not place a grammar file on a web server or similar, you can also directly specify the grammar body gzip-compressed and Base64-encoded in the request.

grammarFileNames=<connection_engine_name|grammar body GZIP-compressed and Base64-encoded>

For example, if you want to use a grammar like the following,

#JSGF V1.0 UTF-8;
grammar test;
public <main> = とりぷるだぶりゅー {www};

gzip-compress and Base64-encode this, and write it in the d parameter as follows. Note that the gzip-compressed and Base64-encoded part does not need to be URL-encoded.

d="grammarFileNames=-a-rule-input-private|H4sIAAAAAAAAClP2CnZ3Uwgz1DNQCA1x07Ww5kovSszNTSxSKEktLrHmKihNyslMVrDJTczMs1OwVXjcuOJxU9fjxu2Pm7ofNy543LgNxG1qfdy8R6G6vLy81hoA9jW921IAAAA="

How to Specify Multiple Grammar Files

You can also specify multiple grammar files. Separate the grammar files with | and list them. This is also applicable when specifying grammar bodies directly.

Example: -a-rule-input-private|test1.gram|test2.gram

Special Speech Recognition Processing Using Multiple Grammar Files

When you use || as the separator between grammar files, special speech recognition processing is performed.

For example, if you specify grammar1||grammar2, recognition processing is first performed using the grammar before || (grammar1), and if recognition succeeds, recognition ends there. If recognition does not succeed, recognition processing is then performed using the grammar after || (grammar2).