/* Callback function for streaming,TTS or bridged calls */
this.onInput = function(s, type, inputEvent, _this) {
- if (type == "event") {
- var speech_type = inputEvent.getHeader("Speech-Type");
- var rv = new Array();
-
- if (!_this.grammar_name) {
- console_log("error", "No Grammar name!\n");
- _this.session.hangup();
- return false;
- }
- var grammar_object = _this.grammar_hash[_this.grammar_name];
-
- if (!grammar_object) {
- console_log("error", "Can't find grammar for " + _this.grammar_name + "\n");
- _this.session.hangup();
- return false;
- }
-
- if (speech_type == "begin-speaking") {
- if (grammar_object.halt) {
+ try {
+ if (type == "event") {
+ var speech_type = inputEvent.getHeader("Speech-Type");
+ var rv = new Array();
+
+ if (!_this.grammar_name) {
+ console_log("error", "No Grammar name!\n");
+ _this.session.hangup();
return false;
}
- } else {
- var body = inputEvent.getBody();
- var interp = new XML(body);
-
- _this.lastDetect = body;
-
- if (_this.debug) {
- console_log("debug", "----XML:\n" + body + "\n");
- console_log("debug", "----Heard [" + interp.input + "]\n");
- console_log("debug", "----Hit score " + interp.@score + "/" + grammar_object.min_score + "/" + grammar_object.confirm_score + "\n");
+
+ var grammar_object = _this.grammar_hash[_this.grammar_name];
+
+ if (!grammar_object) {
+ console_log("error", "Can't find grammar for " + _this.grammar_name + "\n");
+ _this.session.hangup();
+ return false;
}
+
+ if (speech_type == "begin-speaking") {
+ if (grammar_object.halt) {
+ return false;
+ }
+ } else {
+ var body = inputEvent.getBody();
+ var result;
+ var xml;
- if (interp.@score >= grammar_object.min_score) {
- if (interp.@score < grammar_object.confirm_score) {
- rv.push("_confirm_");
+ body = body.replace(/<\?.*?\?>/g, '');
+ xml = new XML("<xml>" + body + "</xml>");
+ result = xml.result;
+
+ _this.lastDetect = body;
+
+ if (_this.debug) {
+ console_log("debug", "----XML:\n" + body + "\n");
+ console_log("debug", "----Heard [" + result.interpretation.input + "]\n");
+ console_log("debug", "----Hit score " + result.interpretation.@confidence + "/" +
+ grammar_object.min_score + "/" + grammar_object.confirm_score + "\n");
}
-
- eval("xo = interp." + grammar_object.obj_path + ";");
- for (x = 0; x < xo.length(); x++) {
- rv.push(xo[x]);
- console_log("info", "----" +xo[x] + "\n");
+
+ if (result.interpretation.@confidence >= grammar_object.min_score) {
+ if (result.interpretation.@confidence < grammar_object.confirm_score) {
+ rv.push("_confirm_");
+ }
+
+ eval("xo = " + grammar_object.obj_path + ";");
+ for (x = 0; x < xo.length(); x++) {
+ rv.push(xo[x]);
+ console_log("info", "----" +xo[x] + "\n");
+ }
+ } else {
+ rv.push("_no_idea_");
}
- } else {
- rv.push("_no_idea_");
+
}
-
+ delete interp;
+ return rv;
}
- delete interp;
- return rv;
+ }
+
+ catch(err) {
+ console_log("crit", "----ERROR:\n" + err + "\n");
}
}
-}
+}
/* Constructor for SpeechObtainer Class (Class to collect data from a SpeechDetect Class) */
function SpeechObtainer(asr, req, wait_time) {
/***************** Delivery Or Take-Out? *****************/
pizza.orderObtainer = new SpeechObtainer(asr, 1, 5000);
-pizza.orderObtainer.setGrammar("pizza_order", "", "result", dft_min, dft_confirm, true);
+pizza.orderObtainer.setGrammar("pizza_order", "", "result.interpretation.input", dft_min, dft_confirm, true);
pizza.orderObtainer.setTopSound("GP-DeliveryorTakeout");
pizza.orderObtainer.setBadSound("GP-NoDeliveryorTake-out");
pizza.orderObtainer.addItemAlias("Delivery", "Delivery");
/***************** What Size? *****************/
pizza.sizeObtainer = new SpeechObtainer(asr, 1, 5000);
-pizza.sizeObtainer.setGrammar("pizza_size", "", "result", dft_min, dft_confirm, true);
+pizza.sizeObtainer.setGrammar("pizza_size", "", "result.interpretation.input", dft_min, dft_confirm, true);
pizza.sizeObtainer.setTopSound("GP-Size");
pizza.sizeObtainer.setBadSound("GP-NI");
pizza.sizeObtainer.addItemAlias("^Extra\\s*Large", "ExtraLarge");
/***************** What Type Of Crust? *****************/
pizza.crustObtainer = new SpeechObtainer(asr, 1, 5000);
-pizza.crustObtainer.setGrammar("pizza_crust", "", "result", dft_min, dft_confirm, true);
+pizza.crustObtainer.setGrammar("pizza_crust", "", "result.interpretation.input", dft_min, dft_confirm, true);
pizza.crustObtainer.setTopSound("GP-Crust");
pizza.crustObtainer.setBadSound("GP-NI");
pizza.crustObtainer.addItemAlias("^Hand\\s*Tossed$,^Tossed$", "HandTossed");
/***************** Specialty Or Custom? *****************/
pizza.typeObtainer = new SpeechObtainer(asr, 1, 5000);
-pizza.typeObtainer.setGrammar("pizza_type", "", "result", dft_min, dft_confirm, true);
+pizza.typeObtainer.setGrammar("pizza_type", "", "result.interpretation.input", dft_min, dft_confirm, true);
pizza.typeObtainer.setTopSound("GP-SpecialtyorCustom");
pizza.typeObtainer.setBadSound("GP-NI");
pizza.typeObtainer.addItemAlias("^Specialty$,^Specialty\\s*pizza$", "Specialty");
/***************** Which Specialty? *****************/
pizza.specialtyObtainer = new SpeechObtainer(asr, 1, 5000);
-pizza.specialtyObtainer.setGrammar("pizza_specialty", "", "result", dft_min, dft_confirm, true);
+pizza.specialtyObtainer.setGrammar("pizza_specialty", "", "result.interpretation.input", dft_min, dft_confirm, true);
pizza.specialtyObtainer.setTopSound("GP-SpecialtyList");
pizza.specialtyObtainer.setBadSound("GP-NI");
pizza.specialtyObtainer.addItemAlias("^Hawaii,^Hawaiian", "Hawaiian");
/***************** What Toppings? *****************/
pizza.toppingsObtainer = new SpeechObtainer(asr, 1, 5000);
-pizza.toppingsObtainer.setGrammar("pizza_toppings", "", "result", dft_min, dft_confirm, true);
+pizza.toppingsObtainer.setGrammar("pizza_toppings", "", "result.interpretation.input", dft_min, dft_confirm, true);
pizza.toppingsObtainer.setTopSound("GP-Toppings");
pizza.toppingsObtainer.setBadSound("GP-NI");
pizza.toppingsObtainer.addItemAlias("anchovie,anchovies", "anchovies");
/***************** Change Delivery Or Size Or Crust, Add/Rem Toppings Or Start Over *****************/
pizza.arsoObtainer = new SpeechObtainer(asr, 1, 5000);
-pizza.arsoObtainer.setGrammar("pizza_arso", "", "result", dft_min, 50, true);
+pizza.arsoObtainer.setGrammar("pizza_arso", "", "result.interpretation.input", dft_min, 50, true);
pizza.arsoObtainer.setTopSound("GP-ARSO");
pizza.arsoObtainer.setBadSound("GP-NI");
pizza.arsoObtainer.addItemAlias("^delivery$", "delivery");
/***************** Yes? No? Maybe So? *****************/
pizza.yesnoObtainer = new SpeechObtainer(asr, 1, 5000);
-pizza.yesnoObtainer.setGrammar("pizza_yesno", "", "result", dft_min, 20, true);
+pizza.yesnoObtainer.setGrammar("pizza_yesno", "", "result.interpretation.input", dft_min, 20, true);
pizza.yesnoObtainer.setBadSound("GP-NI");
pizza.yesnoObtainer.addItemAlias("^yes,^correct", "yes");
pizza.yesnoObtainer.addItemAlias("^no", "no");