/* Create SPEAK request */ static mrcp_message_t* speak_request_create(mrcp_resource_factory_t *factory, apr_pool_t *pool) { mrcp_message_t *message; mrcp_resource_t *resource = mrcp_resource_get(factory,MRCP_SYNTHESIZER_RESOURCE); if(!resource) { return NULL; } apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create SPEAK Request"); message = mrcp_request_create(resource,MRCP_VERSION_2,SYNTHESIZER_SPEAK,pool); if(message) { /* set transparent header fields */ apt_header_field_t *header_field; header_field = apt_header_field_create_c("Content-Type",SAMPLE_CONTENT_TYPE,message->pool); if(header_field) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s: %s",header_field->name.buf,header_field->value.buf); mrcp_message_header_field_add(message,header_field); } header_field = apt_header_field_create_c("Voice-Age",SAMPLE_VOICE_AGE,message->pool); if(header_field) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s: %s",header_field->name.buf,header_field->value.buf); mrcp_message_header_field_add(message,header_field); } /* set message body */ apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set Body: %s",SAMPLE_CONTENT); apt_string_assign(&message->body,SAMPLE_CONTENT,message->pool); } return message; }
/* Create GET-PARAMS response */ static mrcp_message_t* get_params_response_create(mrcp_resource_factory_t *factory, mrcp_message_t *request) { mrcp_message_t *response; apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create GET-PARAMS Response"); response = mrcp_response_create(request,request->pool); if(response) { apt_header_field_t *header_field; header_field = apt_header_field_create_c("Content-Id",SAMPLE_CONTENT_ID,response->pool); if(header_field) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s: %s",header_field->name.buf,header_field->value.buf); mrcp_message_header_field_add(response,header_field); } header_field = apt_header_field_create_c("Vendor-Specific-Params",SAMPLE_PARAM_NAME"="SAMPLE_PARAM_VALUE,response->pool); if(header_field) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s: %s",header_field->name.buf,header_field->value.buf); mrcp_message_header_field_add(response,header_field); } header_field = apt_header_field_create_c("Voice-Age",SAMPLE_VOICE_AGE,response->pool); if(header_field) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s: %s",header_field->name.buf,header_field->value.buf); mrcp_message_header_field_add(response,header_field); } } return response; }
/* Create GET-PARAMS request */ static mrcp_message_t* get_params_request_create(mrcp_resource_factory_t *factory, apr_pool_t *pool) { mrcp_message_t *message; mrcp_resource_t *resource = mrcp_resource_get(factory,MRCP_SYNTHESIZER_RESOURCE); if(!resource) { return NULL; } apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create GET-PARAMS Request"); message = mrcp_request_create(resource,MRCP_VERSION_2,SYNTHESIZER_GET_PARAMS,pool); if(message) { apt_header_field_t *header_field; header_field = apt_header_field_create_c("Content-Id","",message->pool); if(header_field) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s:",header_field->name.buf); mrcp_message_header_field_add(message,header_field); } header_field = apt_header_field_create_c("Vendor-Specific-Params",SAMPLE_PARAM_NAME,message->pool); if(header_field) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s:",header_field->name.buf); mrcp_message_header_field_add(message,header_field); } header_field = apt_header_field_create_c("Voice-Age","",message->pool); if(header_field) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s:",header_field->name.buf); mrcp_message_header_field_add(message,header_field); } } return message; }
/* Set parameters in an MRCP header. */ int speech_channel_set_params(speech_channel_t *schannel, mrcp_message_t *msg, apr_hash_t *header_fields) { if (schannel && msg && header_fields) { /* Loop through each param and add to the message. */ apr_hash_index_t *hi = NULL; for (hi = apr_hash_first(NULL, header_fields); hi; hi = apr_hash_next(hi)) { char *param_name = NULL; char *param_val = NULL; const void *key; void *val; apr_hash_this(hi, &key, NULL, &val); param_name = (char *)key; param_val = (char *)val; if (param_name && (strlen(param_name) > 0) && param_val && (strlen(param_val) > 0)) { ast_log(LOG_DEBUG, "(%s) %s: %s\n", schannel->name, param_name, param_val); apt_header_field_t *header_field = apt_header_field_create_c(param_name, param_val, msg->pool); if(header_field) { if(mrcp_message_header_field_add(msg, header_field) == FALSE) { ast_log(LOG_WARNING, "Error setting MRCP header %s=%s\n", param_name, param_val); } } } } } return 0; }
/* Create SPEAK-COMPLETE event */ static mrcp_message_t* speak_event_create(mrcp_resource_factory_t *factory, const mrcp_message_t *request) { mrcp_message_t *event_message; apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create SPEAK-COMPLETE Event"); event_message = mrcp_event_create(request,SYNTHESIZER_SPEAK_COMPLETE,request->pool); if(event_message) { apt_header_field_t *header_field; header_field = apt_header_field_create_c("Completion-Cause","000 normal",event_message->pool); if(header_field) { mrcp_message_header_field_add(event_message,header_field); } /* set request state */ event_message->start_line.request_state = MRCP_REQUEST_STATE_COMPLETE; } return event_message; }