tweak javascript
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13909 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
1deab52304
commit
70f4d93c3c
|
@ -148,59 +148,72 @@ function SpeechDetect(session, mod, ip) {
|
|||
|
||||
/* 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 (interp.@score >= grammar_object.min_score) {
|
||||
if (interp.@score < grammar_object.confirm_score) {
|
||||
rv.push("_confirm_");
|
||||
}
|
||||
|
||||
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 (speech_type == "begin-speaking") {
|
||||
if (grammar_object.halt) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
rv.push("_no_idea_");
|
||||
}
|
||||
var body = inputEvent.getBody();
|
||||
var result;
|
||||
var xml;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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_");
|
||||
}
|
||||
|
||||
}
|
||||
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) {
|
||||
|
|
|
@ -54,7 +54,7 @@ var pizza = new Object();
|
|||
|
||||
/***************** 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");
|
||||
|
@ -62,7 +62,7 @@ pizza.orderObtainer.addItemAlias("Takeout,Pickup", "Pickup");
|
|||
|
||||
/***************** 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");
|
||||
|
@ -73,7 +73,7 @@ pizza.sizeObtainer.addItemAlias("^Humongous$,^Huge$,^Totally\\s*Humongous$,^Tota
|
|||
|
||||
/***************** 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");
|
||||
|
@ -83,7 +83,7 @@ pizza.crustObtainer.addItemAlias("^New\\s*York,^Thin", "Thin");
|
|||
|
||||
/***************** 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");
|
||||
|
@ -92,7 +92,7 @@ pizza.typeObtainer.addItemAlias("^pick", "Custom");
|
|||
|
||||
/***************** 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");
|
||||
|
@ -104,7 +104,7 @@ pizza.specialtyObtainer.addItemAlias("^Veg", "Vegetarian");
|
|||
|
||||
/***************** 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");
|
||||
|
@ -130,7 +130,7 @@ pizza.toppingsObtainer.addItemAlias("ham", "ham");
|
|||
|
||||
/***************** 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");
|
||||
|
@ -142,7 +142,7 @@ pizza.arsoObtainer.addItemAlias("^remove\\s*", "rem_topping");
|
|||
|
||||
/***************** 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");
|
||||
|
|
Loading…
Reference in New Issue