Problem Getting RECOG_INSTANCE() Value When Using MRCPRecog with Asterisk-Java AGI

64 Views Asked by At

I am running some operations over Asterisk-Java AGI (Asterisk Gateway Interface) using MRCPRecog. There is a problem I am facing with the results from MRCPRecog.

The result returned by MRCPRecog is as follows:

<result xmlns="http://www.w3.org/2000/xforms">
    <interpretation grammar="4791780161253090829" confidence="99">
        <input mode="speech">edirne</input>
        <instance> Edirne;
        </instance>
    </interpretation>
</result>

Which I try to retreive with this code:

String recogConfidence = channel.getVariable("RECOG_CONFIDENCE()");
String recogInput = channel.getVariable("RECOG_INPUT()");

But recogConfidence is null.

When I print the same value in dialplan with this:

 same => n,Verbose(Instance: ${RECOG_INSTANCE()})

I can see the value properly.

I also tried the following methods:

String recogInstance = channel.getVariable("RECOG_INSTANCE(1/1)")

String recogInstance = channel.getVariable("RECOG_INSTANCE(0/1)")

How can I get this value in my AGI code?

2

There are 2 best solutions below

0
On BEST ANSWER

I would like to share my difficulties and the solution.

While searching for the source of the problem, I couldn't find a direct method to get the recog_instance parameter between Asterisk AGI and unimrcp module with java. In this link unimrcp google group post, they suggested that updating the unimrcp module might be useful. I have not tried this suggestion, but it might be an option for you.

Actually, I could observe both in the logs and with tcpdump that the value was being sent to AGI from Asterisk, but somehow, due to buffer size or some other issue, I could not get the value with channel.getVariable.

I tried several different methods until I found my own solution. Finally, I solved it by following these steps

When running SR with MRCPRecog, set the uer parameter to 1.

channel.exec("MRCPRecog", grammar + "," + "p=tredas-sr&spl=tr-TR&t=" + timeout + "&uer=1");

Get the answer returned by the unimrcp function.

String recogInstance2 = channel.getFullVariable("${RECOG_RESULT}");

After that use getLastReplay() to get the response to the last command sent to Asterisk.

String replyString = channel.getLastReply().getFirstLine();

If there are more lines you can use channel.getLastReply().getLines();

Example RECOG_RESULT:

200 result=1 (%3C%3Fxml%20version%3D%221.0%22%3F%3E%0A%3Cresult%09xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fxforms%22%3E%0A%09%3Cinterpretation%20grammar%3D%221548224983940169419%22%20confidence%3D%2271%22%3E%0A%09%09%3Cinput%20mode%3D%22speech%22%3Egaziosmanpa%C5%9Fa%20mah%3C%2Finput%3E%0A%09%09%3Cinstance%3E%0A%09%09%09Gazi%20Osman%20Pa%C5%9Fa%3B%0A%09%09%3C%2Finstance%3E%0A%09%3C%2Finterpretation%3E%0A%3C%2Fresult%3E%0A)

This piece of code allowed me to get the recog result unencoded by uer. Then, using XML parser, I extracted the values I wanted and successfully solved my problem.

I hope this information is useful for you

0
On

On asterisk, you can enable debugging using

asterisk -r
agi set debug on

After that compare what you see with what is in specification. It may send FULL VARIABLE or VARIABLE depend of library version.

If it send correct, check source code of library.