On Friday, August 10, 2012 5:18:55 PM UTC-5, Hernan P. wrote:
Hi,We are trying to integrate Asterisk and Nuance with UniMRCP. After a successful installation, we are using the sample dialplan extension that comes with UniMRCP to test speech recognition in Asterisk:
exten => ts,1,Answer()
exten => ts,2,SpeechCreate()
exten => ts,3,SpeechLoadGrammar(digit,/usr/local/unimrcp/data/grammar.xml)
exten => ts,4,SpeechActivateGrammar(digit)
exten => ts,5,SpeechBackground(hello-world,20)
exten => ts,6,GotoIf($["${SPEECH(results)}" = "0"]?7:9)
exten => ts,7,Playback(vm-nonumber)
exten => ts,8,Goto(5)
exten => ts,9,Verbose(1,The recognized input is ${SPEECH_TEXT(0)})
exten => ts,n,Verbose(1,The score is ${SPEECH_SCORE(0)})
exten => ts,n,Verbose(1,The matched grammar is ${SPEECH_GRAMMAR(0)})
exten => ts,n,SpeechDeactivateGrammar(digit)
exten => ts,n,SpeechUnloadGrammar(digit)
exten => ts,n,SpeechDestroy()
exten => ts,n,Hangup()
The problem: The variable SPEECH_TEXT is always empty. The SPEECH_SCORE and SPEECH_GRAMMAR get valid values though. No errors show up in the logs.
I looked at the logs and Asterisk is getting the recognition NLSML from Nuance server:
<?xml version='1.0'?><result><interpretation grammar="session:digit" confidence="0.78"><input mode="speech">two</input><instance><SWI_literal>two</SWI_literal><SWI_grammarName>session:digit</SWI_grammarName><SWI_meaning>{SWI_literal:two}</SWI_meaning></instance></interpretation></result>
However, the log then shows:
NOTICE[20673] res_speech_unimrcp.c: Interpreted instance:none score:78 grammar:digit
I compared to the result.xml that comes with UniMRCP:
<?xml version="1.0"?>
<result>
<interpretation grammar="session:request1@form-level.store" confidence="97">
<instance>one</instance>
<input mode="speech">one</input>
</interpretation>
</result>
...and I noticed that Nuance's response has more elements under <instance>.
So I thought that UniMRCP may not be parsing the NLSML response correctly. This is what I found in res-speech-unimrcp.c source file:
/** \brief Try to get result */
struct ast_speech_result* uni_recog_get(struct ast_speech *speech)
{
[...]
interpret = nlsml_first_interpret_get(doc);
if(interpret) {
apr_xml_elem *instance;
apr_xml_elem *input;
/* Get instance and input */
nlsml_interpret_results_get(interpret,&instance,&input);
if(instance && input) {
const char *confidence;
const char *grammar;
speech->results = ast_calloc(sizeof(struct ast_speech_result), 1);
speech->results->text = NULL;
speech->results->score = 0;
if(instance->first_cdata.first) {
speech->results->text = strdup(instance->first_cdata.first->text);
}
confidence = nlsml_input_attrib_get(instance,"confidence",TRUE);
if(confidence) {
if(uni_speech->mrcp_event->start_line.version == MRCP_VERSION_2) {
speech->results->score = (int)(atof(confidence) * 100);
}
else {
speech->results->score = atoi(confidence);
}
}
grammar = nlsml_input_attrib_get(interpret,"grammar",TRUE);
if(grammar) {
grammar = strchr(grammar,':');
if(grammar && *grammar != '\0') {
grammar++;
speech->results->grammar = strdup(grammar);
}
}
ast_log(LOG_NOTICE, "Interpreted instance:%s score:%d grammar:%s\n",
speech->results->text ? speech->results->text : "none",
speech->results->score,
speech->results->grammar ? speech->results->grammar : "none");
ast_set_flag(speech,AST_SPEECH_HAVE_RESULTS);
}
}
return speech->results;
}
...From what I understand, it looks like it is trying to find the text as the first element in <instance>, and maybe that is why the string is always empty?
The question is: What is the correct way of fixing this problem? Changing res-speech-unimrcp.c code? or trying to make nuance send an xml that UniMRCP is expecting? Or is the root of this problem somewhere else and I am missing something? Anyone with previous experience integrating with Nuance that could point me in the right direction?
Thanks a lot in advance,
Hernan Palombo