add common for asr and tts FLAG_HAS_MESSAGE to indicate there is a mrcp message to process; fix processing of some mrcp responses and events.
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5660 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
b3454792b1
commit
b6256a4fc8
|
@ -62,14 +62,9 @@
|
||||||
#include "mrcp_recognizer.h"
|
#include "mrcp_recognizer.h"
|
||||||
#include "mrcp_synthesizer.h"
|
#include "mrcp_synthesizer.h"
|
||||||
#include "mrcp_generic_header.h"
|
#include "mrcp_generic_header.h"
|
||||||
#include "mrcp_resource_set.h"
|
|
||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
#define OPENMRCP_WAIT_TIMEOUT 5000
|
|
||||||
#define MY_BUF_LEN 1024 * 128
|
|
||||||
#define MY_BLOCK_SIZE MY_BUF_LEN
|
|
||||||
|
|
||||||
SWITCH_MODULE_LOAD_FUNCTION(mod_openmrcp_load);
|
SWITCH_MODULE_LOAD_FUNCTION(mod_openmrcp_load);
|
||||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openmrcp_shutdown);
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openmrcp_shutdown);
|
||||||
SWITCH_MODULE_DEFINITION(mod_openmrcp, mod_openmrcp_load,
|
SWITCH_MODULE_DEFINITION(mod_openmrcp, mod_openmrcp_load,
|
||||||
|
@ -95,12 +90,9 @@ typedef struct {
|
||||||
} openmrcp_session_t;
|
} openmrcp_session_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
FLAG_HAS_TEXT = (1 << 0),
|
FLAG_HAS_MESSAGE = (1 << 0),
|
||||||
FLAG_BARGE = (1 << 1),
|
FLAG_FEED_STARTED = (1 << 1),
|
||||||
FLAG_READY = (1 << 2),
|
FLAG_TERMINATING = (1 << 2)
|
||||||
FLAG_SPEAK_COMPLETE = (1 << 3),
|
|
||||||
FLAG_FEED_STARTED = (1 << 4),
|
|
||||||
FLAG_TERMINATING = (1 << 5)
|
|
||||||
} mrcp_flag_t;
|
} mrcp_flag_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -220,38 +212,19 @@ static mrcp_status_t openmrcp_on_channel_modify(mrcp_client_context_t *context,
|
||||||
return MRCP_STATUS_FAILURE;
|
return MRCP_STATUS_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mrcp_message->start_line.message_type != MRCP_MESSAGE_TYPE_EVENT) {
|
if (mrcp_message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE && mrcp_message->start_line.request_state == MRCP_REQUEST_STATE_INPROGRESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ignoring mrcp response\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ignoring mrcp response\n");
|
||||||
return MRCP_STATUS_SUCCESS;
|
return MRCP_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mrcp msg body: %s\n", mrcp_message->body);
|
if (switch_test_flag(openmrcp_session, FLAG_HAS_MESSAGE)) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "already has message\n");
|
||||||
|
return MRCP_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
if (mrcp_message->channel_id.resource_id == MRCP_RESOURCE_RECOGNIZER) {
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "setting FLAG_HAS_MESSAGE\n");
|
||||||
if (mrcp_message->start_line.method_id == RECOGNIZER_RECOGNITION_COMPLETE) {
|
openmrcp_session->mrcp_message_last_rcvd = mrcp_message;
|
||||||
openmrcp_session->mrcp_message_last_rcvd = mrcp_message;
|
switch_set_flag_locked(openmrcp_session, FLAG_HAS_MESSAGE);
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "setting FLAG_HAS_TEXT\n");
|
|
||||||
switch_set_flag_locked(openmrcp_session, FLAG_HAS_TEXT);
|
|
||||||
}
|
|
||||||
else if (mrcp_message->start_line.method_id == RECOGNIZER_START_OF_INPUT) {
|
|
||||||
openmrcp_session->mrcp_message_last_rcvd = mrcp_message;
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "setting FLAG_BARGE\n");
|
|
||||||
switch_set_flag_locked(openmrcp_session, FLAG_BARGE);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "ignoring event: %s\n", mrcp_message->start_line.method_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(mrcp_message->channel_id.resource_id == MRCP_RESOURCE_SYNTHESIZER) {
|
|
||||||
if (mrcp_message->start_line.method_id == SYNTHESIZER_SPEAK_COMPLETE) {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setting FLAG_SPEAK_COMPLETE\n");
|
|
||||||
switch_set_flag_locked(openmrcp_session, FLAG_SPEAK_COMPLETE);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "ignoring event: %s\n", mrcp_message->start_line.method_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return MRCP_STATUS_SUCCESS;
|
return MRCP_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,8 +446,8 @@ static switch_status_t openmrcp_asr_check_results(switch_asr_handle_t *ah, switc
|
||||||
{
|
{
|
||||||
openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
|
openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
|
||||||
|
|
||||||
switch_status_t rv = (switch_test_flag(asr_session, FLAG_HAS_TEXT) || switch_test_flag(asr_session, FLAG_BARGE)) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
|
switch_status_t rv = (switch_test_flag(asr_session, FLAG_HAS_MESSAGE)) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,50 +456,61 @@ static switch_status_t openmrcp_asr_get_results(switch_asr_handle_t *ah, char **
|
||||||
{
|
{
|
||||||
openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
|
openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
|
||||||
switch_status_t ret = SWITCH_STATUS_SUCCESS;
|
switch_status_t ret = SWITCH_STATUS_SUCCESS;
|
||||||
|
mrcp_message_t *message;
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "openmrcp_asr_get_results called\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "openmrcp_asr_get_results called\n");
|
||||||
|
|
||||||
if (switch_test_flag(asr_session, FLAG_BARGE)) {
|
message = asr_session->mrcp_message_last_rcvd;
|
||||||
switch_clear_flag_locked(asr_session, FLAG_BARGE);
|
asr_session->mrcp_message_last_rcvd = NULL;
|
||||||
ret = SWITCH_STATUS_BREAK;
|
// since we are returning our result here, future calls to check_results
|
||||||
}
|
// should return False
|
||||||
|
switch_clear_flag_locked(asr_session, FLAG_HAS_MESSAGE);
|
||||||
if (switch_test_flag(asr_session, FLAG_HAS_TEXT)) {
|
|
||||||
/*!
|
|
||||||
we have to extract the XML but stripping off the <?xml version="1.0"?>
|
|
||||||
header. the body looks like:
|
|
||||||
|
|
||||||
Completion-Cause:001 no-match
|
|
||||||
Content-Type: application/nlsml+xml
|
|
||||||
Content-Length: 260
|
|
||||||
|
|
||||||
<?xml version="1.0"?>
|
|
||||||
<result xmlns="http://www.ietf.org/xml/ns/mrcpv2" xmlns:ex="http://www.example.com/example" score="100" grammar="session:request1@form-level.store">
|
|
||||||
<interpretation> <input mode="speech">open a</input>
|
|
||||||
</interpretation>
|
|
||||||
</result>
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(asr_session->mrcp_message_last_rcvd && asr_session->mrcp_message_last_rcvd->body) {
|
if (message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
|
||||||
char *marker = "?>"; // FIXME -- lame and brittle way of doing this. use regex or better.
|
if (message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS &&
|
||||||
char *position = strstr(asr_session->mrcp_message_last_rcvd->body, marker);
|
message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS_WITH_IGNORE) {
|
||||||
if (!position) {
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "error code received [%d]\n", message->start_line.status_code);
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bad result received from mrcp server: %s", asr_session->mrcp_message_last_rcvd->body);
|
|
||||||
ret = SWITCH_STATUS_FALSE;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
position += strlen(marker);
|
|
||||||
*xmlstr = strdup(position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No result received from mrcp server\n");
|
|
||||||
ret = SWITCH_STATUS_FALSE;
|
ret = SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
|
||||||
|
if (message->start_line.method_id == RECOGNIZER_RECOGNITION_COMPLETE) {
|
||||||
|
/*!
|
||||||
|
we have to extract the XML but stripping off the <?xml version="1.0"?>
|
||||||
|
header. the body looks like:
|
||||||
|
|
||||||
|
Completion-Cause:001 no-match
|
||||||
|
Content-Type: application/nlsml+xml
|
||||||
|
Content-Length: 260
|
||||||
|
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<result xmlns="http://www.ietf.org/xml/ns/mrcpv2" xmlns:ex="http://www.example.com/example" score="100" grammar="session:request1@form-level.store">
|
||||||
|
<interpretation> <input mode="speech">open a</input>
|
||||||
|
</interpretation>
|
||||||
|
</result>
|
||||||
|
*/
|
||||||
|
|
||||||
// since we are returning our result here, future calls to check_results
|
if(message->body) {
|
||||||
// should return False
|
char *marker = "?>"; // FIXME -- lame and brittle way of doing this. use regex or better.
|
||||||
switch_clear_flag_locked(asr_session, FLAG_HAS_TEXT);
|
char *position = strstr(message->body, marker);
|
||||||
ret = SWITCH_STATUS_SUCCESS;
|
if (!position) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bad result received from mrcp server: %s", message->body);
|
||||||
|
ret = SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
position += strlen(marker);
|
||||||
|
*xmlstr = strdup(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No result received from mrcp server\n");
|
||||||
|
ret = SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
else if (message->start_line.method_id == RECOGNIZER_START_OF_INPUT) {
|
||||||
|
ret = SWITCH_STATUS_BREAK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -658,10 +642,25 @@ static switch_status_t openmrcp_read_tts(switch_speech_handle_t *sh, void *data,
|
||||||
media_frame_t media_frame;
|
media_frame_t media_frame;
|
||||||
audio_source_t *audio_source;
|
audio_source_t *audio_source;
|
||||||
|
|
||||||
if (switch_test_flag(tts_session, FLAG_SPEAK_COMPLETE)) {
|
if (switch_test_flag(tts_session, FLAG_HAS_MESSAGE)) {
|
||||||
/* tell fs we are done */
|
mrcp_message_t *message = tts_session->mrcp_message_last_rcvd;
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FLAG_SPEAK_COMPLETE\n");
|
tts_session->mrcp_message_last_rcvd = NULL;
|
||||||
return SWITCH_STATUS_BREAK;
|
switch_clear_flag_locked(tts_session, FLAG_HAS_MESSAGE);
|
||||||
|
|
||||||
|
if (message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
|
||||||
|
if (message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS &&
|
||||||
|
message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS_WITH_IGNORE) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "error code received [%d]\n", message->start_line.status_code);
|
||||||
|
return SWITCH_STATUS_BREAK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
|
||||||
|
if (message->start_line.method_id == SYNTHESIZER_SPEAK_COMPLETE) {
|
||||||
|
/* tell fs we are done */
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FLAG_SPEAK_COMPLETE\n");
|
||||||
|
return SWITCH_STATUS_BREAK;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
audio_source = mrcp_client_audio_source_get(tts_session->audio_channel);
|
audio_source = mrcp_client_audio_source_get(tts_session->audio_channel);
|
||||||
|
|
Loading…
Reference in New Issue