[Freeswitch-svn] [commit] r3299 - in freeswitch/trunk: scripts/js_modules src/mod/languages/mod_spidermonkey
Freeswitch SVN
anthm at freeswitch.org
Thu Nov 9 20:40:23 EST 2006
Author: anthm
Date: Thu Nov 9 20:40:22 2006
New Revision: 3299
Modified:
freeswitch/trunk/scripts/js_modules/SpeechTools.jm
freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
Log:
update
Modified: freeswitch/trunk/scripts/js_modules/SpeechTools.jm
==============================================================================
--- freeswitch/trunk/scripts/js_modules/SpeechTools.jm (original)
+++ freeswitch/trunk/scripts/js_modules/SpeechTools.jm Thu Nov 9 20:40:22 2006
@@ -155,19 +155,19 @@
if (!_this.grammar_name) {
console_log("error", "No Grammar name!\n");
_this.session.hangup();
- return;
+ 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;
+ return false;
}
if (speech_type == "begin-speaking") {
if (grammar_object.halt) {
- return;
+ return false;
}
} else {
var body = inputEvent.getBody();
@@ -176,29 +176,27 @@
_this.lastDetect = body;
if (_this.debug) {
- console_log("debug", "----XML:\n" + body);
+ console_log("debug", "----XML:\n" + body + "\n");
console_log("debug", "----Heard [" + interp.input + "]\n");
- console_log("debug", "----Hit score " + interp. at score + "\n");
+ console_log("debug", "----Hit score " + interp. at score + "/" + grammar_object.min_score + "/" + grammar_object.confirm_score + "\n");
}
-
- if (interp. at score < grammar_object.min_score) {
- delete interp;
- rv.push("_no_idea_");
- return rv;
- } else {
+
+ 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]);
}
-
- delete interp;
- return rv;
+ } else {
+ rv.push("_no_idea_");
}
+
+ console_log("debug", "dammit: " + rv + "\n");
+ delete interp;
+ return rv;
}
}
}
@@ -331,16 +329,27 @@
this.react = function(say_str, play_str) {
var rv;
- this.asr.resume();
- if (this.tts_eng && this.tts_voice) {
- rv = this.speak(say_str);
- } else {
- rv = this.streamFile(play_str);
+
+ if (!rv) {
+ rv = this.asr.session.collectInput(this.asr.onInput, this.asr, 500);
}
if (!rv) {
+ this.asr.resume();
+ if (this.tts_eng && this.tts_voice) {
+ rv = this.speak(say_str);
+ } else {
+ rv = this.streamFile(play_str);
+ }
+ }
+
+ if (!rv) {
rv = this.asr.session.collectInput(this.asr.onInput, this.asr, 500);
}
+ if (rv && !rv[0]) {
+ rv = false;
+ }
+
return rv;
}
@@ -374,8 +383,16 @@
}
hit = false;
if (rv) {
- for (y = 0; y < rv.length; y++) {
- if (rv[y] == "_confirm_") {
+ var items = rv;
+ rv = undefined;
+ for (y = 0; y < items.length; y++) {
+ if (items[y] == "_no_idea_") {
+ if (this.debug) {
+ console_log("debug", "----We don't understand this\n");
+ }
+ break;
+ }
+ if (items[y] == "_confirm_") {
this.needConfirm = true;
if (this.debug) {
console_log("debug", "----We need to confirm this one\n");
@@ -385,10 +402,10 @@
for(x = 0 ; x < this.index; x++) {
if (this.debug) {
- console_log("debug", "----Testing " + rv[y] + " =~ [" + this.items[x] + "]\n");
+ console_log("debug", "----Testing [" + y + "] [" + x + "] " + items[y] + " =~ [" + this.items[x] + "]\n");
}
var re = new RegExp(this.items[x]);
- match = re.exec(rv[y]);
+ match = re.exec(items[y]);
if (match) {
for (i = 0; i < match.length; i++) {
dup = false;
@@ -419,7 +436,7 @@
}
if (!rv) {
- rv = this.asr.session.collectInput(this.asr.onInput, this.asr, 500);
+ rv = this.asr.session.collectInput(this.asr.onInput, this.asr, 1000);
}
if (!rv && !hit && !dup) {
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c (original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c Thu Nov 9 20:40:22 2006
@@ -547,7 +547,8 @@
if ((status = js_common_callback(session, input, itype, buf, buflen)) != SWITCH_STATUS_SUCCESS) {
return status;
}
-
+
+
if ((ret = JS_GetStringBytes(JS_ValueToString(cb_state->cx, cb_state->ret)))) {
if (!strncasecmp(ret, "speed", 4)) {
char *p;
@@ -611,10 +612,11 @@
}
if (!strcmp(ret, "true") || !strcmp(ret, "undefined")) {
- return SWITCH_STATUS_SUCCESS;
- }
+ return SWITCH_STATUS_SUCCESS;
+ }
return SWITCH_STATUS_BREAK;
+
}
return SWITCH_STATUS_SUCCESS;
}
@@ -646,10 +648,11 @@
}
if (!strcmp(ret, "true") || !strcmp(ret, "undefined")) {
- return SWITCH_STATUS_SUCCESS;
- }
-
+ return SWITCH_STATUS_SUCCESS;
+ }
+
return SWITCH_STATUS_BREAK;
+
}
return SWITCH_STATUS_SUCCESS;
@@ -669,9 +672,11 @@
if (!strcmp(ret, "true") || !strcmp(ret, "undefined")) {
return SWITCH_STATUS_SUCCESS;
}
- return SWITCH_STATUS_BREAK;
}
+ return SWITCH_STATUS_BREAK;
+
+
return SWITCH_STATUS_SUCCESS;
}
@@ -749,7 +754,7 @@
memset(&fh, 0, sizeof(fh));
cb_state.extra = &fh;
-
+ cb_state.ret = BOOLEAN_TO_JSVAL( JS_FALSE );
switch_ivr_record_file(jss->session, &fh, file_name, dtmf_func, bp, len);
*rval = cb_state.ret;
@@ -794,7 +799,7 @@
}
switch_ivr_collect_digits_callback(jss->session, dtmf_func, bp, len, to);
- *rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, cb_state.ret_buffer));
+ *rval = cb_state.ret;
return (switch_channel_ready(channel)) ? JS_TRUE : JS_FALSE;
}
@@ -848,7 +853,7 @@
memset(&fh, 0, sizeof(fh));
cb_state.extra = &fh;
-
+ cb_state.ret = BOOLEAN_TO_JSVAL( JS_FALSE );
switch_ivr_play_file(jss->session, &fh, file_name, timer_name, dtmf_func, bp, len);
*rval = cb_state.ret;
@@ -948,8 +953,8 @@
}
}
- if (argc > 4) {
- timer_name = JS_GetStringBytes(JS_ValueToString(cx, argv[4]));
+ if (argc > 5) {
+ timer_name = JS_GetStringBytes(JS_ValueToString(cx, argv[5]));
}
if (!tts_name && text) {
@@ -957,6 +962,7 @@
}
codec = switch_core_session_get_read_codec(jss->session);
+ cb_state.ret = BOOLEAN_TO_JSVAL( JS_FALSE );
switch_ivr_speak_text(jss->session,
tts_name,
voice_name && strlen(voice_name) ? voice_name : NULL,
More information about the Freeswitch-svn
mailing list