diff --git a/app-unimrcp/app_datastore.c b/app-unimrcp/app_datastore.c
index cad4c79..c5508fe 100644
--- a/app-unimrcp/app_datastore.c
+++ b/app-unimrcp/app_datastore.c
@@ -266,6 +266,7 @@ app_session_t* app_datastore_session_add(app_datastore_t* app_datastore, const c
session->nlsml_result = NULL;
session->stop_barged_synth = FALSE;
session->instance_format = NLSML_INSTANCE_FORMAT_XML;
+ session->replace_new_lines = 0;
ast_log(LOG_DEBUG, "Add entry %s to datastore on %s\n", entry, ast_channel_name(app_datastore->chan));
apr_hash_set(app_datastore->session_table, entry, APR_HASH_KEY_STRING, session);
}
@@ -553,6 +554,17 @@ static const apr_xml_elem* recog_instance_find_elem(const apr_xml_elem *elem, co
return NULL;
}
+static int recog_instance_replace_char(char *str, char find_char, char replace_char)
+{
+ char *ptr = str;
+ int n = 0;
+ while ((ptr = strchr(ptr, find_char)) != NULL) {
+ *ptr++ = replace_char;
+ n++;
+ }
+ return n;
+}
+
/* Helper function used to process XML data in NLSML instance */
static int recog_instance_process_xml(app_session_t *app_session, nlsml_instance_t *instance, const char *path, const char **text)
{
@@ -700,6 +712,9 @@ static int recog_instance(struct ast_channel *chan, const char *cmd, char *data,
return -1;
ast_copy_string(buf, text, len);
+ if (app_session->replace_new_lines) {
+ recog_instance_replace_char(buf, '\n', app_session->replace_new_lines);
+ }
return 0;
}
diff --git a/app-unimrcp/app_datastore.h b/app-unimrcp/app_datastore.h
index 6be9729..240e602 100644
--- a/app-unimrcp/app_datastore.h
+++ b/app-unimrcp/app_datastore.h
@@ -64,6 +64,7 @@ struct app_session_t {
nlsml_result_t *nlsml_result; /* parsed NLSML result */
apt_bool_t stop_barged_synth; /* whether or not to always stop barged synthesis request */
enum nlsml_instance_format instance_format; /* NLSML instance format */
+ char replace_new_lines; /* replace new lines in NLSML instance */
};
typedef struct app_session_t app_session_t;
diff --git a/app-unimrcp/app_mrcprecog.c b/app-unimrcp/app_mrcprecog.c
index 7c62493..166dc30 100644
--- a/app-unimrcp/app_mrcprecog.c
+++ b/app-unimrcp/app_mrcprecog.c
@@ -115,6 +115,7 @@
+
@@ -160,7 +161,8 @@ enum mrcprecog_option_flags {
MRCPRECOG_INPUT_TIMERS = (1 << 8),
MRCPRECOG_PERSISTENT_LIFETIME = (1 << 9),
MRCPRECOG_DATASTORE_ENTRY = (1 << 10),
- MRCPRECOG_INSTANCE_FORMAT = (1 << 11)
+ MRCPRECOG_INSTANCE_FORMAT = (1 << 11),
+ MRCPRECOG_REPLACE_NEW_LINES = (1 << 12)
};
/* The enumeration of option arguments. */
@@ -177,9 +179,10 @@ enum mrcprecog_option_args {
OPT_ARG_PERSISTENT_LIFETIME = 9,
OPT_ARG_DATASTORE_ENTRY = 10,
OPT_ARG_INSTANCE_FORMAT = 11,
+ OPT_ARG_REPLACE_NEW_LINES = 12,
/* This MUST be the last value in this enum! */
- OPT_ARG_ARRAY_SIZE = 12
+ OPT_ARG_ARRAY_SIZE = 13
};
/* The enumeration of plocies for the use of input timers. */
@@ -951,6 +954,9 @@ static int mrcprecog_option_apply(mrcprecog_options_t *options, const char *key,
} else if (strcasecmp(key, "nif") == 0) {
options->flags |= MRCPRECOG_INSTANCE_FORMAT;
options->params[OPT_ARG_INSTANCE_FORMAT] = value;
+ } else if (strcasecmp(key, "rnl") == 0) {
+ options->flags |= MRCPRECOG_REPLACE_NEW_LINES;
+ options->params[OPT_ARG_REPLACE_NEW_LINES] = value;
} else {
ast_log(LOG_WARNING, "Unknown option: %s\n", key);
}
@@ -1235,6 +1241,15 @@ static int app_recog_exec(struct ast_channel *chan, ast_app_data data)
}
}
+ /* Check whether new lines shall be replaced */
+ if ((mrcprecog_options.flags & MRCPRECOG_REPLACE_NEW_LINES) == MRCPRECOG_REPLACE_NEW_LINES) {
+ if (!ast_strlen_zero(mrcprecog_options.params[OPT_ARG_REPLACE_NEW_LINES])) {
+ char ch = *mrcprecog_options.params[OPT_ARG_REPLACE_NEW_LINES];
+ ast_log(LOG_DEBUG, "(%s) Replace new lines: %c\n", name, ch);
+ app_session->replace_new_lines = ch;
+ }
+ }
+
const char *grammar_delimiters = ",";
/* Get grammar delimiters. */
if ((mrcprecog_options.flags & MRCPRECOG_GRAMMAR_DELIMITERS) == MRCPRECOG_GRAMMAR_DELIMITERS) {
diff --git a/app-unimrcp/app_synthandrecog.c b/app-unimrcp/app_synthandrecog.c
index 16b6430..ab5f6e5 100644
--- a/app-unimrcp/app_synthandrecog.c
+++ b/app-unimrcp/app_synthandrecog.c
@@ -93,6 +93,7 @@
+
@@ -138,7 +139,8 @@ enum sar_option_flags {
SAR_PERSISTENT_LIFETIME = (1 << 7),
SAR_DATASTORE_ENTRY = (1 << 8),
SAR_STOP_BARGED_SYNTH = (1 << 9),
- SAR_INSTANCE_FORMAT = (1 << 10)
+ SAR_INSTANCE_FORMAT = (1 << 10),
+ SAR_REPLACE_NEW_LINES = (1 << 11)
};
/* The enumeration of option arguments. */
@@ -154,9 +156,10 @@ enum sar_option_args {
OPT_ARG_DATASTORE_ENTRY = 8,
OPT_ARG_STOP_BARGED_SYNTH = 9,
OPT_ARG_INSTANCE_FORMAT = 10,
+ OPT_ARG_REPLACE_NEW_LINES = 11,
/* This MUST be the last value in this enum! */
- OPT_ARG_ARRAY_SIZE = 11
+ OPT_ARG_ARRAY_SIZE = 12
};
/* The enumeration of plocies for the use of input timers. */
@@ -1165,6 +1168,9 @@ static int synthandrecog_option_apply(sar_options_t *options, const char *key, c
} else if (strcasecmp(key, "nif") == 0) {
options->flags |= SAR_INSTANCE_FORMAT;
options->params[OPT_ARG_INSTANCE_FORMAT] = value;
+ } else if (strcasecmp(key, "rnl") == 0) {
+ options->flags |= SAR_REPLACE_NEW_LINES;
+ options->params[OPT_ARG_REPLACE_NEW_LINES] = value;
} else {
ast_log(LOG_WARNING, "Unknown option: %s\n", key);
}
@@ -1525,6 +1531,15 @@ static int app_synthandrecog_exec(struct ast_channel *chan, ast_app_data data)
}
}
+ /* Check whether new lines shall be replaced */
+ if ((sar_options.flags & SAR_REPLACE_NEW_LINES) == SAR_REPLACE_NEW_LINES) {
+ if (!ast_strlen_zero(sar_options.params[OPT_ARG_REPLACE_NEW_LINES])) {
+ char ch = *sar_options.params[OPT_ARG_REPLACE_NEW_LINES];
+ ast_log(LOG_DEBUG, "(%s) Replace new lines: %c\n", recog_name, ch);
+ app_session->replace_new_lines = ch;
+ }
+ }
+
/* Get grammar delimiters. */
const char *grammar_delimiters = ",";
if ((sar_options.flags & SAR_GRAMMAR_DELIMITERS) == SAR_GRAMMAR_DELIMITERS) {