Finalization of speech detect interface and API

This changes the core to have the necessary tools to create
a speech detection interface.

It also changes the code in javascript (mod_spidermonkey)
there are a few api changes in how it handles callbacks

It also adds grammars as a system dir to store asr grammars




git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3291 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2006-11-09 05:39:04 +00:00
1 parent b942d8e044
commit 44fc26f7d4
20 files changed
+1996 -540

No files matched your search

@@ -393,10 +393,12 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
switch_channel_t *caller_channel;
switch_core_session_t *caller_session;
char *argv[7] = {0};
int x, argc = 0;
int i = 0, x, argc = 0;
char *aleg, *exten, *dp, *context, *cid_name, *cid_num;
uint32_t timeout = 60;
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
uint8_t machine = 1;
if (isession) {
stream->write_function(stream, "Illegal Usage\n");
return SWITCH_STATUS_SUCCESS;
@@ -414,13 +416,18 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
argv[x] = NULL;
}
}
if (!strcasecmp(argv[0], "machine")) {
machine = 1;
i++;
}
aleg = argv[0];
exten = argv[1];
dp = argv[2];
context = argv[3];
cid_name = argv[4];
cid_num = argv[5];
aleg = argv[i++];
exten = argv[i++];
dp = argv[i++];
context = argv[i++];
cid_name = argv[i++];
cid_num = argv[i++];
if (!dp) {
dp = "XML";
@@ -435,7 +442,11 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
}
if (switch_ivr_originate(NULL, &caller_session, &cause, aleg, timeout, &noop_state_handler, cid_name, cid_num, NULL) != SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "Cannot Create Outgoing Channel! [%s]\n", aleg);
if (machine) {
stream->write_function(stream, "fail: %s", switch_channel_cause2str(cause));
} else {
stream->write_function(stream, "Cannot Create Outgoing Channel! [%s] cause: %s\n", aleg, switch_channel_cause2str(cause));
}
return SWITCH_STATUS_SUCCESS;
}
@@ -467,7 +478,13 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
} else {
switch_ivr_session_transfer(caller_session, exten, dp, context);
}
stream->write_function(stream, "Created Session: %s\n", switch_core_session_get_uuid(caller_session));
if (machine) {
stream->write_function(stream, "success: %s\n", switch_core_session_get_uuid(caller_session));
} else {
stream->write_function(stream, "Created Session: %s\n", switch_core_session_get_uuid(caller_session));
}
return SWITCH_STATUS_SUCCESS;;
}
@@ -666,7 +666,7 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, v
switch_memory_pool_t *pool;
if (conference->fnode->type == NODE_TYPE_SPEECH) {
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_TTS;
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
switch_core_speech_close(&conference->fnode->sh, &flags);
} else {
switch_core_file_close(&conference->fnode->fh);
@@ -957,7 +957,7 @@ static void conference_loop(conference_member_t *member)
switch_memory_pool_t *pool;
if (member->fnode->type == NODE_TYPE_SPEECH) {
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_TTS;
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
switch_core_speech_close(&member->fnode->sh, &flags);
} else {
switch_core_file_close(&member->fnode->fh);
@@ -1340,7 +1340,7 @@ static switch_status_t conference_member_say(conference_obj_t *conference, confe
{
confernce_file_node_t *fnode, *nptr;
switch_memory_pool_t *pool;
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_TTS;
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
if (!(conference->tts_engine && conference->tts_voice)) {
return SWITCH_STATUS_SUCCESS;
@@ -1399,7 +1399,7 @@ static switch_status_t conference_say(conference_obj_t *conference, char *text,
{
confernce_file_node_t *fnode, *nptr;
switch_memory_pool_t *pool;
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_TTS;
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
uint32_t count;
switch_mutex_lock(conference->mutex);
+36 -3
View File
@@ -34,6 +34,33 @@
static const char modname[] = "mod_dptools";
static const switch_application_interface_t detect_speech_application_interface;
static void detect_speech_function(switch_core_session_t *session, char *data)
{
char *argv[4];
int argc;
char *lbuf = NULL;
if ((lbuf = switch_core_session_strdup(session, data)) && (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
if (!strcasecmp(argv[0], "grammar") && argc >= 1) {
switch_ivr_detect_speech_load_grammar(session, argv[1], argv[2]);
} else if (!strcasecmp(argv[0], "nogrammar")) {
switch_ivr_detect_speech_unload_grammar(session, argv[1]);
} else if (!strcasecmp(argv[0], "pause")) {
switch_ivr_pause_detect_speech(session);
} else if (!strcasecmp(argv[0], "resume")) {
switch_ivr_resume_detect_speech(session);
} else if (!strcasecmp(argv[0], "stop")) {
switch_ivr_stop_detect_speech(session);
} else if (argc >= 3) {
switch_ivr_detect_speech(session, argv[0], argv[1], argv[2], argv[3], NULL);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", detect_speech_application_interface.syntax);
}
}
static void ringback_function(switch_core_session_t *session, char *data)
{
@@ -253,7 +280,6 @@ static switch_api_interface_t dptools_api_interface = {
/*.next */ &chat_api_interface
};
static switch_api_interface_t presence_api_interface = {
/*.interface_name */ "presence",
/*.desc */ "presence",
@@ -262,6 +288,14 @@ static switch_api_interface_t presence_api_interface = {
/*.next */ &dptools_api_interface
};
static const switch_application_interface_t detect_speech_application_interface = {
/*.interface_name */ "detect_speech",
/*.application_function */ detect_speech_function,
/* long_desc */ "Detect speech on a channel.",
/* short_desc */ "Detect speech",
/* syntax */ "<mod_name> <gram_name> <gram_path> [<addr>] OR grammar <gram_name> [<path>] OR pause OR resume",
/*.next */ NULL
};
static const switch_application_interface_t ringback_application_interface = {
/*.interface_name */ "ringback",
@@ -269,8 +303,7 @@ static const switch_application_interface_t ringback_application_interface = {
/* long_desc */ "Indicate Ringback on a channel.",
/* short_desc */ "Indicate Ringback",
/* syntax */ "",
/*.next */ NULL
/*.next */ &detect_speech_application_interface
};
static const switch_application_interface_t set_application_interface = {
+125 -1
View File
@@ -167,6 +167,123 @@ static void tts_function(switch_core_session_t *session, char *data)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Done\n");
}
#if 1
static void asrtest_function(switch_core_session_t *session, char *data)
{
switch_ivr_detect_speech(session,
"lumenvox",
"demo",
data,
"127.0.0.1",
NULL);
}
#else
static void asrtest_function(switch_core_session_t *session, char *data)
{
switch_asr_handle_t ah = {0};
switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
switch_channel_t *channel = switch_core_session_get_channel(session);
char *codec_name = "L16";
switch_codec_t codec = {0}, *read_codec;
switch_frame_t write_frame = {0}, *write_frame_p = NULL;
char xdata[1024] = "";
read_codec = switch_core_session_get_read_codec(session);
assert(read_codec != NULL);
if (switch_core_asr_open(&ah, "lumenvox",
read_codec->implementation->iananame,
8000,
"127.0.0.1",
&flags,
switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
if (strcmp(ah.codec, read_codec->implementation->iananame)) {
if (switch_core_codec_init(&codec,
ah.codec,
NULL,
ah.rate,
read_codec->implementation->microseconds_per_frame / 1000,
read_codec->implementation->number_of_channels,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
switch_core_session_set_read_codec(session, &codec);
write_frame.data = xdata;
write_frame.buflen = sizeof(xdata);
write_frame.codec = &codec;
write_frame_p = &write_frame;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Activation Failed %s@%uhz %u channels %dms\n",
codec_name, read_codec->implementation->samples_per_second, read_codec->implementation->number_of_channels,
read_codec->implementation->microseconds_per_frame / 1000);
switch_core_session_reset(session);
return;
}
}
if (switch_core_asr_load_grammar(&ah, "demo", "/opt/lumenvox/engine_7.0/Lang/BuiltinGrammars/ABNFPhone.gram") != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error loading Grammar\n");
goto end;
}
while(switch_channel_ready(channel)) {
switch_frame_t *read_frame;
switch_status_t status = switch_core_session_read_frame(session, &read_frame, -1, 0);
char *xmlstr = NULL;
switch_xml_t xml = NULL, result;
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
if (switch_test_flag(read_frame, SFF_CNG)) {
continue;
}
if (switch_core_asr_feed(&ah, read_frame->data, read_frame->datalen, &flags) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error Feeding Data\n");
break;
}
if (switch_core_asr_check_results(&ah, &flags) == SWITCH_STATUS_SUCCESS) {
if (switch_core_asr_get_results(&ah, &xmlstr, &flags) != SWITCH_STATUS_SUCCESS) {
break;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "RAW XML\n========\n%s\n", xmlstr);
if ((xml = switch_xml_parse_str(xmlstr, strlen(xmlstr))) && (result = switch_xml_child(xml, "result"))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Results [%s]\n", result->txt);
switch_xml_free(xml);
}
switch_safe_free(xmlstr);
}
if (write_frame_p) {
write_frame.datalen = read_frame->datalen;
switch_core_session_write_frame(session, write_frame_p, -1, 0);
} else {
memset(read_frame->data, 0, read_frame->datalen);
switch_core_session_write_frame(session, read_frame, -1, 0);
}
}
end:
if (write_frame_p) {
switch_core_session_set_read_codec(session, read_codec);
switch_core_codec_destroy(&codec);
}
switch_core_asr_close(&ah, &flags);
switch_core_session_reset(session);
}
}
#endif
static void ivrtest_function(switch_core_session_t *session, char *data)
{
switch_channel_t *channel;
@@ -272,13 +389,20 @@ static const switch_application_interface_t ivrtest_application_interface = {
/*.next*/ &dirtest_application_interface
};
static const switch_application_interface_t asrtest_application_interface = {
/*.interface_name */ "asrtest",
/*.application_function */ asrtest_function,
NULL, NULL, NULL,
/*.next*/ &ivrtest_application_interface
};
static const switch_loadable_module_interface_t mod_ivrtest_module_interface = {
/*.module_name = */ modname,
/*.endpoint_interface = */ NULL,
/*.timer_interface = */ NULL,
/*.dialplan_interface = */ NULL,
/*.codec_interface = */ NULL,
/*.application_interface */ &ivrtest_application_interface
/*.application_interface */ &asrtest_application_interface
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
+1 -1
View File
@@ -169,7 +169,7 @@ static void rss_function(switch_core_session_t *session, char *data)
char *voice = TTS_DEFAULT_VOICE;
char *timer_name = NULL;
switch_speech_handle_t sh;
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_TTS;
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
switch_core_thread_session_t thread_session;
uint32_t rate, interval = 20;
int stream_id = 0;