From 08a90638d35c07bb9d2800e34b0159d2e468a7b9 Mon Sep 17 00:00:00 2001 From: Arsen Chaloyan Date: Tue, 20 Jun 2017 17:00:03 -0700 Subject: [PATCH] Allow built-in and HTTP grammars be specified with SpeechActivateGrammar(). For example: SpeechActivateGrammar(builtin:speech/transcribe) SpeechActivateGrammar(builtin:dtmf/digits) SpeechBackground() --- res-speech-unimrcp/res_speech_unimrcp.c | 43 +++++++++++++++++-------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/res-speech-unimrcp/res_speech_unimrcp.c b/res-speech-unimrcp/res_speech_unimrcp.c index 0e41325..ef9ff67 100644 --- a/res-speech-unimrcp/res_speech_unimrcp.c +++ b/res-speech-unimrcp/res_speech_unimrcp.c @@ -597,30 +597,47 @@ static int uni_recog_start(struct ast_speech *speech) /* Get/allocate generic header */ generic_header = mrcp_generic_header_prepare(mrcp_message); if(generic_header) { + char *tmp; + char buf[1024]; + int length; + int total_length = 0; apr_hash_index_t *it; void *val; const char *grammar_name; const char *content = NULL; + apt_bool_t first_line = TRUE; + /* Set generic header fields */ apt_string_assign(&generic_header->content_type,"text/uri-list",mrcp_message->pool); mrcp_generic_header_property_add(mrcp_message,GENERIC_HEADER_CONTENT_TYPE); - /* Construct and set message body */ - it = apr_hash_first(mrcp_message->pool,uni_speech->active_grammars); - if(it) { - apr_hash_this(it,NULL,NULL,&val); - grammar_name = val; - content = apr_pstrcat(mrcp_message->pool,"session:",grammar_name,NULL); - it = apr_hash_next(it); - } - for(; it; it = apr_hash_next(it)) { + /* Compose and set message body */ + for(it = apr_hash_first(mrcp_message->pool,uni_speech->active_grammars); it; it = apr_hash_next(it)) { apr_hash_this(it,NULL,NULL,&val); grammar_name = val; - content = apr_pstrcat(mrcp_message->pool,content,"\nsession:",grammar_name,NULL); - } - if(content) { - apt_string_set(&mrcp_message->body,content); + + if(first_line == TRUE) + first_line = FALSE; + else + buf[total_length++] = '\n'; + + tmp = strchr(grammar_name,':'); + if(tmp) { + ast_log(LOG_DEBUG, "(%s) Reference grammar %s\n",uni_speech->name, grammar_name); + length = apr_snprintf(buf + total_length, sizeof(buf) - 1 - total_length, "%s", grammar_name); + } + else { + ast_log(LOG_DEBUG, "(%s) Reference session grammar %s\n",uni_speech->name, grammar_name); + length = apr_snprintf(buf + total_length, sizeof(buf) - 1 - total_length, "session:%s", grammar_name); + } + if(length < 0) { + ast_log(LOG_WARNING, "(%s) Failed to compose MRCP message body\n",uni_speech->name); + return -1; + } + total_length += length; } + buf[total_length] = '\0'; + apt_string_assign_n(&mrcp_message->body,buf,total_length,mrcp_message->pool); } /* Get/allocate recognizer header */