Velocity powered by Wavelink

> Managing Projects > Using Speakeasy > Grammar Files > Grammar File Structure

This page refers to an older version of the product.
View the current version of the User Guide.

Grammar File Structure

Grammar files must follow a specific structure for Speakeasy to correctly interpret the file's contents.

The following example is a basic grammar file:

#BNF+EM V2.1;

/*

GRAMMAR: usa_states.bnf

 

Description:

This is a grammar file that recognizes some states of the USA.

 

What Can I Say?

You can say any of the following American states.

*/

 

!grammar usa_states;

!start <state>;

 

<state>:

  Alabama

| Alaska

| Connecticut

| Florida

| Idaho

| Kansas

| "New Jersey"

| "New York"

If you would like a copy of a demo grammar file, you can download it from here. With this file, you can alter it as needed for your own use.

#BNF+EM V1.1;

Each grammar file must begin with a statement such as #BNF+EM V1.1; that identifies how Speakeasy should handle the grammar file. You do not need to modify this line.

/* */ or //

To create comments — information ignored by the engine — you can begin a line with // or enclose text in /* and */ markers. You can edit the Description and the What Can I Say? sections to describe changes you make to the grammar file.

!grammar [filename]

If you change the name of the grammar file, the command !grammar must use the new file name. For example, if the name of the file was changed to VoicePick.bnf, the command would read: !grammar VoicePick;.

!start <state>;

The !start command specifies which group of terms in the grammar will be available when the grammar is in use. In the above example, the engine will listen for all of the terms in the <Speech> rule. If multiple rules existed and only one was referenced by the command, all other rules are ignored.

<state>: Alabama | Connecticut |...

The words and phrases listed between <Speech>: and the last ; are the terms the grammar will accept. Each word or phrase must be separated by | (the equivalent of an OR symbol). Terms may be listed all on the same line or aligned vertically for easier editing.

To improve recognition for terms that may be similar to others, such as New York and New Jersey, enclose the phrase in "" (quotations). This forces the Speakeasy engine to compare the accepted phrase more closely against the user response.

Subsections

In some grammar files, the main rule <Speech> is divided into subsections to make it easier to manage the terms.

!start <Speech>;

<Speech>: <YesNo> | <Maybe>;
<YesNo>: yes | no;
<Maybe>: maybe;

In this example, the <Speech> rule includes the <YesNo> and the <Maybe> rules, so the engine will listen for all the terms in both the <YesNo> rule and the <Maybe> rule.


This page refers to an older version of the product.
View the current version of the User Guide.

The topic was:

Inaccurate

Incomplete

Not what I expected

Other