[Freeswitch-trunk] [commit] r13909 - in freeswitch/trunk/scripts: . js_modules

FreeSWITCH SVN brian at freeswitch.org
Tue Jun 23 08:22:56 PDT 2009


Author: brian
Date: Tue Jun 23 10:22:55 2009
New Revision: 13909

Log:
 tweak javascript 

Modified:
   freeswitch/trunk/scripts/js_modules/SpeechTools.jm
   freeswitch/trunk/scripts/ps_pizza.js

Modified: freeswitch/trunk/scripts/js_modules/SpeechTools.jm
==============================================================================
--- freeswitch/trunk/scripts/js_modules/SpeechTools.jm	(original)
+++ freeswitch/trunk/scripts/js_modules/SpeechTools.jm	Tue Jun 23 10:22:55 2009
@@ -148,59 +148,72 @@
 
 	/* 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. at 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. at score >= grammar_object.min_score) {
-					if (interp. at 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. at confidence + "/" + 
+									grammar_object.min_score + "/" + grammar_object.confirm_score + "\n");
+					}
+		  
+					if (result.interpretation. at confidence >= grammar_object.min_score) {
+						if (result.interpretation. at 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) {

Modified: freeswitch/trunk/scripts/ps_pizza.js
==============================================================================
--- freeswitch/trunk/scripts/ps_pizza.js	(original)
+++ freeswitch/trunk/scripts/ps_pizza.js	Tue Jun 23 10:22:55 2009
@@ -54,7 +54,7 @@
 
 /***************** 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 @@
 
 /***************** 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 @@
 
 /***************** 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 @@
 
 /***************** 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 @@
 
 /***************** 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 @@
 
 /***************** 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 @@
 
 /***************** 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 @@
 
 /***************** 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");



More information about the Freeswitch-trunk mailing list