Sometimes you need to test your grammar independently of using voice input. For this reason LumenVox provides a few objects for validating text sentences. These objects are LVSpeechGrammar, LVTextParser, and TextParseTree.
#include <LVSpeechGrammar.h>
#include <TextParseTree.h>
#include <iostream>
#include <string>
//callback function to log grammar compilation messages.
void GrammarCB(const char* msg, int warning_level, void* ignore_me) {
string error;
if (warning_level = LV_SPEECH_GRAMMAR_WARNING) error += "WARNING: ";
else error += "ERROR: ";
error += msg;
cout << error << endl;
}
int main() {
LVSpeechGrammar Grammar;
Grammar.RegisterLoggingCallback(GrammarCB, NULL);
Grammar.LoadGrammarFromFile("c:\\phone_numbers.gram");
LVTextParser Parser(Grammar); //compiles the grammar into a parsing tool.
int num_parses = Parser.ParseText("area code eight five eight seven o seven o seven o seven");
TextParseTree T;
cout << "Number of parses: " << num_parses << endl;
for (int i = 0; i < num_parses; ++i) {
T = Parser.GetParseTree(i);
TextParseTree::PreOrderIterator Itr = T.PreOrderBegin();
TextParseTree::PreOrderIterator End = T.PreOrderEnd();
for (; Itr != End; ++Itr) if (Itr->IsTag()) //print just the tags in this tree.
cout << T->Label() << " ";
}
}
Complete Help Topic List | Speech Engine Product Information