Grammar file structure
Grammar files must follow a specific structure for Speakeasy to correctly interpret the file's contents.
The following is an example of the contents of 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";
#BNF+EM V2.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 <state> 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 <state>: and the last ; are the terms the grammar will accept. Each word or phrase must be separated by | (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 "" (quotation marks). This forces the Speakeasy engine to compare the accepted phrase more closely against the user response.
Multiple rules
In some grammar files, the main rule is divided into subsections to make it easier to manage the terms. If you have multiple rules in a file, make sure that are all included in the rule that is used on the !start line.
!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.
Similar terms
If you have words that sound similar, you may get poor recognition results. To improve recognition, use longer and more distinct phrases. For example, rather than use similar terms like “faster” and “fastest,” replace them with phrases like “go faster” and “warp speed”.