Skip to content

Commit

Permalink
Allow built-in and HTTP grammars be specified with SpeechActivateGram…
Browse files Browse the repository at this point in the history
…mar().

For example:

   SpeechActivateGrammar(builtin:speech/transcribe)
   SpeechActivateGrammar(builtin:dtmf/digits)
   SpeechBackground()
  • Loading branch information
achaloyan committed Jun 21, 2017
1 parent 7244b5e commit 08a9063
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions res-speech-unimrcp/res_speech_unimrcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 08a9063

Please sign in to comment.