How do I migrate from L&H BNF V1.0 to V2.0?

Last reviewed: 7/15/2011

HOW Article ID: H071103

The information in this article applies to:

  • Developer Workbench 2011
  • GrammarKit 4
  • SpeechKit 7

Summary

Chant Developer Workbench 2011, GrammarKit 4, and SpeechKit 7 provide support for L&H BNF V1.0, V1.1, and V2.0 grammars.

More Information

The L&H BNF grammar is a Backus-Naur Form (BNF) grammar adapted for speech recognition. There are 3 syntax versions: V1.0, V1.1, and V2.0.

The #BNF+EM V1.0; statement that appears as the first line in the grammar defines the syntax version.

Creating, Editing, and Testing L&H BNF Grammars

Chant Developer Workbench 2011 introduces support for creating, editing, and testing all three versions of L&H BNF grammar syntax. The updated editors provide intelliprompt assistance for fast syntax input and editing.

The steps to create an L&H BNF grammar with Chant Developer Workbench and GrammarKit are as follows:

  1. Select the File->New->Speech Recognition Grammar->L&H BNF V1.0 Grammar menu item or click the New Standard toolbar button and select L&H BNF V1.0 Grammar to create a V1.0 grammar in a document window.
  2. Select the File->New->Speech Recognition Grammar->L&H BNF V1.1 Grammar menu item or click the New Standard toolbar button and select L&H BNF V1.1 Grammar to create a V1.1 grammar in a document window.
  3. Select the File->New->Speech Recognition Grammar->L&H BNF V2.0 Grammar menu item or click the New Standard toolbar button and select L&H BNF V2.0 Grammar to create a V2.0 grammar in a document window. Note if you do not see any grammar types listed in the menu, then you need to run the Chant Software Unlock utility to begin your evaluation, your GrammarKit evaluation has expired, or you need to register and unlock your licensed copy with a serial number.
  4. Save your new grammar to a file by selecting the File->Save menu item or click the Save Standard toolbar button. You are prompted to confirm the file name.

Dynamically Generating L&H BNF Version-specific Grammars

GrammarKit 4 introduces support for dynamically generating and compiling L&H BNF version-specific grammars.

The following example illustrates generating a L&H BNF grammar:


private Chant.GrammarKit.NChantGM NChantGM1;
private NChantGrammar _NChantGrammar = null;
// Instantiate NChantGM object
NChantGM1 = new NChantGM(this);
NChantGM1.SetNumberProperty(ChantNumberProperty.CNPEngineAPI, (int)ChantEngineAPI.CEVoCon4);
// Win32 - Set the path to the VoCon runtime libraries
NChantGM1.SetStringProperty(ChantStringProperty.CSPEnginePath, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\bin\\winx86rls");
// Win32 - Set the file name of CLC model
NChantGM1.SetStringProperty(ChantStringProperty.CSPCLCModel, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\clc_enu_cfg3_v1_0_0.dat");
// Win32 - Or set the file name of DDG2P model
//NChantGM1.SetStringProperty(ChantStringProperty.CSPDDG2PModel, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\ddg2p_enu_vadvde_ttsasr_large_v2_1_3.dat");
// Build Colors grammar
_NChantGrammar = NChantGM1.CreateGrammar("Colors");
_NChantGrammar.AddComment("This is the list of colors");
NChantGrammarRule nChantGrammarRule = _NChantGrammar.AddRule("Color");
NChantGrammarList nChantGrammarList = nChantGrammarRule.AddList("colorlist");
string[] colors = { "red", "blue", "green", "yellow", "pink", "purple", "brown", "orange" };
for (int i = 0; i < colors.Length; i++)
{
    nChantGrammarList.AddPhrase(colors[i]);
}
// Generate L&H V1.0 grammar
string grammarSource = _NChantGrammar.GenerateGrammar(ChantGrammarSyntax.CGSVoConBNF);
// Generate L&H V1.1 grammar
string grammarSource = _NChantGrammar.GenerateGrammar(ChantGrammarSyntax.CGSVoConBNF1);
// Generate L&H V2.0 grammar
string grammarSource = _NChantGrammar.GenerateGrammar(ChantGrammarSyntax.CGSVoConBNF2);
       

CChantGM* m_pChantGM;  // ChantGM object
CChantGrammar* m_pChantGrammar;  // ChantGrammar object
// Instantiate ChantGM object
m_pChantGM = new CChantGM();
m_pChantGM->SetNumberProperty(CNPEngineAPI, CEVoCon4);
// Win32 - Set the path to the VoCon runtime libraries
m_pChantGM->SetStringProperty(CSPEnginePath, L"C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\bin\\winx86rls");
// Win32 - Set the file name of CLC model
m_pChantGM->SetStringProperty(CSPCLCModel, L"C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\clc_enu_cfg3_v1_0_0.dat");
// Win32 - Or set the file name of DDG2P model
//m_pChantGM->SetStringProperty(CSPDDG2PModel, L"C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\ddg2p_enu_vadvde_ttsasr_large_v2_1_3.dat");
// Build Colors grammar
m_pChantGrammar = m_pChantGM->CreateGrammar(L"Colors");
m_pChantGrammar->AddComment(L"This is the list of colors");
CChantGrammarRule* pChantGrammarRule = m_pChantGrammar->AddRule(L"Color");
CChantGrammarList* pChantGrammarList = pChantGrammarRule->AddList(L"colorlist");
wchar_t* colors[] = { L"red", L"blue", L"green", L"yellow", L"pink", L"purple", L"brown", L"orange" };
for (int i = 0; i < 8; i++)
{
    pChantGrammarList->AddPhrase(colors[i]);
}
// Generate L&H V1.0 grammar
wchar_t* pszGrammar = m_pChantGrammar->GenerateGrammar(CGSVoConBNF);
// Generate L&H V1.1 grammar
wchar_t* pszGrammar = m_pChantGrammar->GenerateGrammar(CGSVoConBNF1);
// Generate L&H V2.0 grammar
wchar_t* pszGrammar = m_pChantGrammar->GenerateGrammar(CGSVoConBNF2);
    

CChantGM* ChantGM1;  // ChantGM object
CChantGrammar* ChantGrammar1;  // ChantGrammar object
// Instantiate ChantGM object
ChantGM1 = new CChantGM();
ChantGM1->SetNumberProperty(CNPEngineAPI, CEVoCon4);
// Win32 - Set the path to the VoCon runtime libraries
ChantGM1->SetStringProperty(CSPEnginePath, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\bin\\winx86rls");
// Win32 - Set the file name of CLC model
ChantGM1->SetStringProperty(CSPCLCModel, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\clc_enu_cfg3_v1_0_0.dat");
// Win32 - Or set the file name of DDG2P model
//ChantGM1->SetStringProperty(CSPDDG2PModel, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\ddg2p_enu_vadvde_ttsasr_large_v2_1_3.dat");
// Build Colors grammar
ChantGrammar1 = ChantGM1->CreateGrammar("Colors");
ChantGrammar1->AddComment("This is the list of colors");
CChantGrammarRule* pChantGrammarRule = ChantGrammar1->AddRule("Color");
CChantGrammarList* pChantGrammarList = pChantGrammarRule->AddList("colorlist");
pChantGrammarList->AddPhrase("red");
pChantGrammarList->AddPhrase("blue");
pChantGrammarList->AddPhrase("green");
pChantGrammarList->AddPhrase("yellow");
pChantGrammarList->AddPhrase("pink");
pChantGrammarList->AddPhrase("purple");
pChantGrammarList->AddPhrase("brown");
pChantGrammarList->AddPhrase("orange");
// Generate L&H V1.0 grammar
String sGrammar = ChantGrammar1->GenerateGrammar(CGSVoConBNF);
// Generate L&H V1.1 grammar
String sGrammar = ChantGrammar1->GenerateGrammar(CGSVoConBNF1);
// Generate L&H V2.0 grammar
String sGrammar = ChantGrammar1->GenerateGrammar(CGSVoConBNF2);

var
ChantGM1: TChantGM;
aTChantGrammar: TChantGrammar;
aTChantGrammarRule: TChantGrammarRule;
aTChantGrammarList: TChantGrammarList;
sGrammar: string;
begin
    // Instantiate ChantGM object
    ChantGM1 := TChantGM.Create();
    ChantGM1.SetNumberProperty(CNPEngineAPI, CEVoCon4);
    // Win32 - Set the path to the VoCon runtime libraries
    ChantGM1.SetStringProperty(CSPEnginePath, 'C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\bin\\winx86rls');
    // Win32 - Set the file name of CLC model
    ChantGM1.SetStringProperty(CSPCLCModel, 'C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\clc_enu_cfg3_v1_0_0.dat');
    // Win32 - Or set the file name of DDG2P model
    //ChantGM1.SetStringProperty(CSPDDG2PModel, 'C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\ddg2p_enu_vadvde_ttsasr_large_v2_1_3.dat');
    // Build Colors grammar
    aTChantGrammar := ChantGM1.CreateGrammar('Colors');
    aTChantGrammar.AddComment('This is the list of colors');
    aTChantGrammarRule := aTChantGrammar.AddRule('Color');
    aTChantGrammarList := aTChantGrammarRule.AddList('colorlist');
    aTChantGrammarList.AddPhrase('red');
    aTChantGrammarList.AddPhrase('blue');
    aTChantGrammarList.AddPhrase('green');
    aTChantGrammarList.AddPhrase('yellow');
    aTChantGrammarList.AddPhrase('pink');
    aTChantGrammarList.AddPhrase('purple');
    aTChantGrammarList.AddPhrase('brown');
    aTChantGrammarList.AddPhrase('orange');
    // Generate L&H V1.0 grammar
    sGrammar := ChantGrammar.GenerateGrammar(CGSVoConBNF);
    // Generate L&H V1.1 grammar
    sGrammar := ChantGrammar.GenerateGrammar(CGSVoConBNF1);
    // Generate L&H V2.0 grammar
    sGrammar := ChantGrammar.GenerateGrammar(CGSVoConBNF2);
end;
    

private JChantGM JChantGM1;
private JChantGrammar _JChantGrammar;
// Instantiate ChantGM object
JChantGM1 = new JChantGM();
JChantGM1.setNumberProperty(ChantNumberProperty.CNPEngineAPI, ChantEngineAPI.CEVoCon4);
// Win32 - Set the path to the VoCon runtime libraries
JChantGM1.setStringProperty(ChantStringProperty.CSPEnginePath, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\bin\\winx86rls");
// Win32 - Set the file name of CLC model
JChantGM1.setStringProperty(ChantStringProperty.CSPCLCModel, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\clc_enu_cfg3_v1_0_0.dat");
// Win32 - Or set the file name of DDG2P model
//JChantGM1.setStringProperty(ChantStringProperty.CSPDDG2PModel, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\ddg2p_enu_vadvde_ttsasr_large_v2_1_3.dat");
// Build Colors grammar
_JChantGrammar = JChantGM1.createGrammar("Colors");
_JChantGrammar.addComment("This is the list of colors");
JChantGrammarRule jChantGrammarRule = _JChantGrammar.addRule("Color");
JChantGrammarList jChantGrammarList = jChantGrammarRule.addList("colorlist");
String[] colors = { "red", "blue", "green", "yellow", "pink", "purple", "brown", "orange" };
for (int i = 0; i < 8; i++)
{
    jChantGrammarList.addPhrase(colors[i]);
}
// Generate L&H V1.0 grammar
String grammarSource = _JChantGrammar.generateGrammar(ChantGrammarSyntax.CGSVoConBNF);
// Generate L&H V1.1 grammar
String grammarSource = _JChantGrammar.generateGrammar(ChantGrammarSyntax.CGSVoConBNF1);
// Generate L&H V2.0 grammar
String grammarSource = _JChantGrammar.generateGrammar(ChantGrammarSyntax.CGSVoConBNF2);
    

WChantGM1.SetNumberProperty(CNPEngineAPI, CEVoCon4);
// Win32 - Set the path to the VoCon runtime libraries
WChantGM1.SetStringProperty(CSPEnginePath, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\bin\\winx86rls");
// Win32 - Set the file name of CLC model
WChantGM1.SetStringProperty(CSPCLCModel, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\clc_enu_cfg3_v1_0_0.dat");
// Win32 - Or set the file name of DDG2P model
//WChantGM1.SetStringProperty(CSPDDG2PModel, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\ddg2p_enu_vadvde_ttsasr_large_v2_1_3.dat");
// Build Colors grammar
var wChantGrammar = WChantGM1.CreateGrammar("Colors");
wChantGrammar.AddComment("This is the list of colors");
var wChantGrammarRule = wChantGrammar.AddRule("Color");
var wChantGrammarList = wChantGrammarRule.AddList("colorlist");
wTChantGrammarList.AddPhrase("red");
wTChantGrammarList.AddPhrase("blue");
wTChantGrammarList.AddPhrase("green");
wTChantGrammarList.AddPhrase("yellow");
wTChantGrammarList.AddPhrase("pink");
wTChantGrammarList.AddPhrase("purple");
wTChantGrammarList.AddPhrase("brown");
wTChantGrammarList.AddPhrase("orange");
// Generate L&H V1.0 grammar
var sGrammar = wChantGrammar.GenerateGrammar(CGSVoConBNF);
// Generate L&H V1.1 grammar
var sGrammar = wChantGrammar.GenerateGrammar(CGSVoConBNF1);
// Generate L&H V2.0 grammar
var sGrammar = wChantGrammar.GenerateGrammar(CGSVoConBNF2);
    

Dim WithEvents XChantGM1 As XChantGM
Dim aXChantGrammar As XChantGrammar
Dim aXChantGrammarRule As XChantGrammarRule
Dim aXChantGrammarList As XChantGrammarList
Dim sGrammar As String
XChantGM1.SetNumberProperty CNPEngineAPI, CEVoCon4
' Win32 - Set the path to the VoCon runtime libraries
XChantGM1.SetStringProperty CSPEnginePath, "C:\Program Files\Nuance\vocon3200\EDS_v4_1\bin\winx86rls"
// Win32 - Set the file name of CLC model
XChantGM1.SetStringProperty ChantStringProperty.CSPCLCModel, "C:\Program Files\Nuance\vocon3200\EDS_v4_1\models\clc_enu_cfg3_v1_0_0.dat"
// Win32 - Or set the file name of DDG2P model
//XChantGM1.SetStringProperty ChantStringProperty.CSPDDG2PModel, "C:\Program Files\Nuance\vocon3200\EDS_v4_1\models\ddg2p_enu_vadvde_ttsasr_large_v2_1_3.dat"
' Build Colors grammar
Set aXChantGrammar = XChantGM1.CreateGrammar("Colors")
aXChantGrammar.AddComment "This is the list of colors"
Set aXChantGrammarRule = aXChantGrammar.AddRule("Color")
Set aXChantGrammarList = aXChantGrammarRule.AddList("colorlist")
aXChantGrammarList.AddPhrase "red"
aXChantGrammarList.AddPhrase "blue"
aXChantGrammarList.AddPhrase "green"
aXChantGrammarList.AddPhrase "yellow"
aXChantGrammarList.AddPhrase "pink"
aXChantGrammarList.AddPhrase "purple"
aXChantGrammarList.AddPhrase "brown"
aXChantGrammarList.AddPhrase "orange"
' Generate L&H V1.0 grammar
sGrammar = aXChantGrammar.GenerateGrammar(CGSVoConBNF)
' Generate L&H V1.1 grammar
sGrammar = aXChantGrammar.GenerateGrammar(CGSVoConBNF1)
' Generate L&H V2.0 grammar
sGrammar = aXChantGrammar.GenerateGrammar(CGSVoConBNF2)

Dim WithEvents NChantGM1 As NChantGM
Dim _NChantGrammar As NChantGrammar
Dim nChantGrammarRule As NChantGrammarRule
Dim nChantGrammarList As NChantGrammarList
Dim grammarSource As String
' Instantiate ChantGM object
NChantGM1 = New NChantGM(Me)
NChantGM1.SetNumberProperty(ChantNumberProperty.CNPEngineAPI, ChantEngineAPI.CEVoCon4)
' Win32 - Set the path to the VoCon runtime libraries
NChantGM1.SetStringProperty(ChantStringProperty.CSPEnginePath, "C:\Program Files\Nuance\vocon3200\EDS_v4_1\bin\winx86rls")
// Win32 - Set the file name of CLC model
NChantGM1.SetStringProperty(ChantStringProperty.CSPCLCModel, "C:\Program Files\Nuance\vocon3200\EDS_v4_1\models\clc_enu_cfg3_v1_0_0.dat")
// Win32 - Or set the file name of DDG2P model
//NChantGM1.SetStringProperty(ChantStringProperty.CSPDDG2PModel, "C:\Program Files\Nuance\vocon3200\EDS_v4_1\models\ddg2p_enu_vadvde_ttsasr_large_v2_1_3.dat")
' Build Colors grammar
_NChantGrammar = NChantGM1.CreateGrammar("Colors")
_NChantGrammar.AddComment("This is the list of colors")
nChantGrammarRule = _NChantGrammar.AddRule("Color")
nChantGrammarList = nChantGrammarRule.AddList("colorlist")
nChantGrammarList.AddPhrase("red")
nChantGrammarList.AddPhrase("blue")
nChantGrammarList.AddPhrase("green")
nChantGrammarList.AddPhrase("yellow")
nChantGrammarList.AddPhrase("pink")
nChantGrammarList.AddPhrase("purple")
nChantGrammarList.AddPhrase("brown")
nChantGrammarList.AddPhrase("orange")
' Generate L&H V1.0 grammar
grammarSource = _NChantGrammar.GenerateGrammar(ChantGrammarSyntax.CGSVoConBNF)
' Generate L&H V1.1 grammar
grammarSource = _NChantGrammar.GenerateGrammar(ChantGrammarSyntax.CGSVoConBNF1)
' Generate L&H V2.0 grammar
grammarSource = _NChantGrammar.GenerateGrammar(ChantGrammarSyntax.CGSVoConBNF2)

Recognizing with L&H BNF Version-specific Grammars

To recognize speech with L&H BNF version-specific grammar, simply use the SpeechKit ChantSR DefineResource method to define a CSRNativeGrammarVocab (binary) or CSRGrammarVocab (source) resource with the file name of the grammar. Use the EnableResource and DisableResource methods to activate and deactivate the grammar.

VoCon 3200 V2 supports V1.0 grammars. VoCon V3 supports V1.1 grammars. VoCon V4 supports V2.0 grammars.


// Define a grammar vocabulary
int GrammarVocabID = NChantSR1.DefineResource(ChantSpeechResource.CSRGrammarVocab, "mygrammar.bnf");
// Load and enable grammar vocabulary
NChantSR1.EnableResource(ChantSpeechResource.CSRGrammarVocab, grammarVocabID);
// Disable it
NChantSR1.DisableResource(ChantSpeechResource.CSRGrammarVocab, grammarVocabID);
       

// Define a grammar vocabulary
long grammarVocabID;
grammarVocabID = pChantSR->DefineResource(CSRGrammarVocab, L"mygrammar.bnf");
// Load and enable grammar vocabulary
pChantSR->EnableResource(CSRGrammarVocab, grammarVocabID);
// Disable it
pChantSR->DisableResource(CSRGrammarVocab, grammarVocabID);
    

// Define a grammar vocabulary
long grammarVocabID;
grammarVocabID = pChantSR->DefineResource(CSRGrammarVocab, "mygrammar.bnf");
// Load and enable grammar vocabulary
pChantSR->EnableResource(CSRGrammarVocab, grammarVocabID);
// Disable it
pChantSR->DisableResource(CSRGrammarVocab, grammarVocabID);

// Define a grammar vocabulary
var
grammarVocabID: Integer;
begin
    grammarVocabID := ChantSR1.DefineResource(CSRGrammarVocab, 'mygrammar.bnf');
    // Load and enable grammar vocabulary
    ChantSR1.EnableResource(CSRGrammarVocab, grammarVocabID);
    // Disable it
    ChantSR1.DisableResource(CSRGrammarVocab, grammarVocabID);
end;
    

// Define a grammar vocabulary
int grammarVocabID = JChantSR1.defineResource(ChantSpeechResource.CSRGrammarVocab, "mygrammar.bnf");
// Load and enable grammar vocabulary
JChantSR1.enableResource(ChantSpeechResource.CSRGrammarVocab, grammarVocabID);
// Disable it
JChantSR1.disableResource(ChantSpeechResource.CSRGrammarVocab, grammarVocabID);
    

// Define a grammar vocabulary
var grammarVocabID;
grammarVocabID = WChantSR1.DefineResource(CSRGrammarVocab, "file:///c:/mygrammar.bnf");
// Load and enable grammar vocabulary
WChantSR1.EnableResource(CSRGrammarVocab, grammarVocabID);
// Disable it
WChantSR1.DisableResource(CSRGrammarVocab, grammarVocabID);
    

' Define a grammar vocabulary
Dim grammarVocabID as Integer
GrammarVocabID = XChantSR1.DefineResource(CSRGrammarVocab, App.Path & "\mygrammar.bnf")
' Load and enable grammar vocabulary
XChantSR1.EnableResource CSRGrammarVocab, grammarVocabID
' Disable it
XChantSR1.DisableResource CSRGrammarVocab, grammarVocabID

' Define a grammar vocabulary
Dim grammarVocabID As Integer
grammarVocabID = NChantSR1.DefineResource(ChantSpeechResource.CSRGrammarVocab, "mygrammar.bnf")
' Load and enable grammar vocabulary
NChantSR1.EnableResource(ChantSpeechResource.CSRGrammarVocab, grammarVocabID)
' Disable it
NChantSR1.DisableResource(ChantSpeechResource.CSRGrammarVocab, grammarVocabID)