git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3299 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-11-10 01:40:22 +00:00
parent 351480b99b
commit 964e2e9886
2 changed files with 60 additions and 37 deletions

View File

@ -155,19 +155,19 @@ function SpeechDetect(session, mod, ip) {
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 @@ function SpeechDetect(session, mod, ip) {
_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.@score + "\n");
console_log("debug", "----Hit score " + interp.@score + "/" + grammar_object.min_score + "/" + grammar_object.confirm_score + "\n");
}
if (interp.@score < grammar_object.min_score) {
delete interp;
rv.push("_no_idea_");
return rv;
} else {
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]);
}
delete interp;
return rv;
} else {
rv.push("_no_idea_");
}
console_log("debug", "dammit: " + rv + "\n");
delete interp;
return rv;
}
}
}
@ -331,16 +329,27 @@ function SpeechObtainer(asr, req, wait_time) {
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 @@ function SpeechObtainer(asr, req, wait_time) {
}
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 @@ function SpeechObtainer(asr, req, wait_time) {
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 @@ function SpeechObtainer(asr, req, wait_time) {
}
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) {

View File

@ -547,7 +547,8 @@ static switch_status_t js_stream_input_callback(switch_core_session_t *session,
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 @@ static switch_status_t js_stream_input_callback(switch_core_session_t *session,
}
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 @@ static switch_status_t js_record_input_callback(switch_core_session_t *session,
}
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 @@ static switch_status_t js_collect_input_callback(switch_core_session_t *session,
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 @@ static JSBool session_recordfile(JSContext *cx, JSObject *obj, uintN argc, jsval
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 @@ static JSBool session_collect_input(JSContext *cx, JSObject *obj, uintN argc, js
}
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 @@ static JSBool session_streamfile(JSContext *cx, JSObject *obj, uintN argc, jsval
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 @@ static JSBool session_speak(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
}
}
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 @@ static JSBool session_speak(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
}
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,