mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 01:26:58 +00:00
tweak javascript
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13909 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user