How do I manage grammars with Microsoft Speech Platform?
Last reviewed: 3/1/2012
HOW Article ID: H031201
The information in this article applies to:
- GrammarKit 4
Summary
GrammarKit 4 provides support for Microsoft Speech Platform.
More Information
Chant GrammarKit 4 provides support for Microsoft Speech Platform that can generate, compile, and persist grammar binary for SAPI 5 XML and W3C XML speech recognition grammar syntax.
Both 32-bit and 64-bit applications can generate, compile, and persist SAPI 5 XML and W3C XML grammar binary using a Microsoft Speech Platform recognizer. The 32-bit Microsoft Speech Platform runtime must be installed to support 32-bit applications. The 64-bit Microsoft Speech Platform runtime must be installed to support 64-bit applications.
All current Microsoft Speech Platform versions are supported: v10.0, v10.1, v10.2 and v11.0. Only one version may be installed at a time. The runtimes and recognizers (grammar compilers) can be downloaded from Microsoft:
- Microsoft Speech Platform v10.0 Runtimes
- Microsoft Speech Platform v10.0 Recognizer
- Microsoft Speech Platform v10.1 Runtimes
- Microsoft Speech Platform v10.1 Recognizers
- Microsoft Speech Platform v10.2 Runtimes
- Microsoft Speech Platform v10.2 Recognizers
- Microsoft Speech Platform v11.0 Runtimes
- Microsoft Speech Platform v11.0 Recognizers
The grammar compiler can be selected by setting the CSPEngine property to recognizer name or by setting the CNPEngineAPI value to CEMSPSR.
private Chant.GrammarKit.NChantGM NChantGM1;
private NChantGrammar _NChantGrammar = null;
// Instantiate NChantGM object
NChantGM1 = new NChantGM(this);
NChantGM1.SetNumberProperty(ChantNumberProperty.CNPEngineAPI, (int)ChantEngineAPI.CEMSPSR);
// 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]);
}
string grammarSource = _NChantGrammar.GenerateGrammar(ChantGrammarSyntax.CGSSAPI5XML);
// Compile a grammar and save results to file
NChantGM1.CompileResource(grammarSource, 0, ChantCompileObject.CCOText, ChantGrammarSyntax.CGSSAPI5XML, "mygrammar.dat", ChantCompileResult.CCRFile, 0, ChantCompileOption.CCPAsynchronous);
CChantGM* m_pChantGM; // ChantGM object
CChantGrammar* m_pChantGrammar; // ChantGrammar object
// Instantiate ChantGM object
m_pChantGM = new CChantGM();
m_pChantGM->SetNumberProperty(CNPEngineAPI, CEMSPSR);
// 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]);
}
wchar_t* pszGrammar = m_pChantGrammar->GenerateGrammar(CGSSAPI5XML);
// Compile a grammar and save results to file
pChantGM->CompileResource(pszGrammar, 0, CCOText, CGSSAPI5XML, L"mygrammar.dat", CCRFile, 0, CCPAsynchronous);
CChantGM* ChantGM1; // ChantGM object
CChantGrammar* ChantGrammar1; // ChantGrammar object
// Instantiate ChantGM object
ChantGM1 = new CChantGM();
ChantGM1->SetNumberProperty(CNPEngineAPI, CEMSPSR);
// 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");
String sGrammar = ChantGrammar1->GenerateGrammar(CGSSAPI5XML);
// Compile a grammar and save results to file
pChantGM->CompileResource(sGrammar, 0, CCOText, CGSSAPI5XML, "mygrammar.dat", CCRFile, 0, CCPAsynchronous);
var
ChantGM1: TChantGM;
aTChantGrammar: TChantGrammar;
aTChantGrammarRule: TChantGrammarRule;
aTChantGrammarList: TChantGrammarList;
sGrammar: string;
begin
// Instantiate ChantGM object
ChantGM1 := TChantGM.Create();
ChantGM1.SetNumberProperty(CNPEngineAPI, CEMSPSR);
// 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');
sGrammar := ChantGrammar.GenerateGrammar(CGSSAPI5XML);
// Compile a grammar and save results to file
ChantGM1.CompileResource(sGrammar, 0, CCOText, CGSSAPI5XML, 'mygrammar.dat', CCRFile, 0, CCPAsynchronous);
end;
private JChantGM JChantGM1;
private JChantGrammar _JChantGrammar;
// Instantiate ChantGM object
JChantGM1 = new JChantGM();
JChantGM1.setNumberProperty(ChantNumberProperty.CNPEngineAPI, ChantEngineAPI.CEMSPSR);
// 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]);
}
String grammarSource = _JChantGrammar.generateGrammar(ChantGrammarSyntax.CGSSAPI5XML);
// Compile a grammar and save results to file
JChantGM1.compileResource(grammarSource, 0, ChantCompileObject.CCOText, ChantGrammarSyntax.CGSSAPI5XML, "mygrammar.dat", ChantCompileResult.CCRFile, 0, ChantCompileOption.CCPAsynchronous);
WChantGM1.SetNumberProperty(CNPEngineAPI, CEMSPSR);
// 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");
var sGrammar = wChantGrammar.GenerateGrammar(CGSSAPI5XML);
// Compile a grammar and save results to file
WChantGM1.CompileResource(sGrammar, 0, CCOText, CGSSAPI5XML, "mygrammar.dat", CCRFile, 0, CCPAsynchronous);
Dim WithEvents XChantGM1 As XChantGM
Dim aXChantGrammar As XChantGrammar
Dim aXChantGrammarRule As XChantGrammarRule
Dim aXChantGrammarList As XChantGrammarList
Dim sGrammar As String
XChantGM1.SetNumberProperty CNPEngineAPI, CEMSPSR
' 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"
sGrammar = aXChantGrammar.GenerateGrammar(CGSSAPI5XML)
' Compile a grammar and save results to file
XChantGM1.CompileResource sGrammar, 0, CCOText, CGSSAPI5XML, "mygrammar.dat", CCRFile, 0, CCPAsynchronous
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.CEMSPSR)
' 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")
grammarSource = _NChantGrammar.GenerateGrammar(ChantGrammarSyntax.CGSSAPI5XML)
// Compile a grammar and save results to file
NChantGM1.CompileResource(grammarSource, 0, ChantCompileObject.CCOText, ChantGrammarSyntax.CGSSAPI5XML, "mygrammar.dat", ChantCompileResult.CCRFile, 0, ChantCompileOption.CCPAsynchronous)