Retrieving NLSML Instance Fields with RECOG_INSTANCE()

99 views
Skip to first unread message

Arsen Chaloyan

unread,
May 11, 2020, 10:03:10 PM5/11/20
to UniMRCP
Asterisk users,

As you may know, the helper function RECOG_INSTANCE() in app_unimrcp allows to retrieve content of the <instance> element from the returned NLSML results. The content itself may have different semantics based on the technology used. If recognition is performed against an SRGS grammar, the content may contain filled in slots. If used with Dialogflow, Lex, Azure bots, the content is defined by the bot and slightly varies based on the vendor.

The user application was supposed to parse and further process the content by means of external utilities. Since this routine introduces certain challenges, the function RECOG_INSTANCE() has been extended to allow returning individual fields from the <instance> element.

While retaining backwards compatibility, the function RECOG_INSTANCE() now accepts another optional attribute, which specifies a name of the field or a full path down to the field to be retrieved from the content of the <instance> element.

Let's observe the following data structure as an example.

<instance>
<query_text>Sunnyvale</query_text>
<action>room.reservation</action>
<parameters>
<location>
<city>Sunnyvale</city>
</location>
</parameters>
<fulfillment_text>What date?</fulfillment_text>
</instance>

In order to retrieve the content of the <fulfillment text> element, RECOG_INSTANCE(0/0/fulfillment_text) can be used, which will result in "What date?".

In order to retrieve the content of the nested <city> element, RECOG_INSTANCE(0/0/parameters/location/city) can be used, which will result in "Sunnyvale" correspondingly.

You may check out this commit for implementation details.

--
Arsen Chaloyan
Author of UniMRCP
http://www.unimrcp.org

sin...@gmail.com

unread,
Aug 7, 2020, 12:37:49 PM8/7/20
to UniMRCP
hi Arsen,
just found this new function of RECOG_INSTANCE()  ,and i have some problem with that..hope you can see see,thanks.
when i use RECOG_INSTANCE(0/0), there is no result....and it may be "你好“  if it works.
I'am confused with that these days...may be you can easily help me...thanks again.


below is my dialplan:
exten => s,1,Answer
exten => s,n,SynthAndRecog(Hello,Please say something,builtin:grammar/number,t=5000&b=1&ct=0.2&sl=0.8&spl=zh-CN&rm=hotword&uer=1)
exten => s,n,Verbose(1,The recognized extension was ${RECOG_INSTANCE(0/0)})

and here is the log in short:
app_synthandrecog.c:1292 synthandrecog_exit: SynthAndRecog() exiting status: OK on SIP/8001-0000e7e2
    -- Executing [s@synthandrecog-app1:5] Verbose("SIP/8001-0000e7e2", "1,The recognized extension was ") in new stack
 The recognized extension was 
    -- Executing [s@synthandrecog-app1:6] Verbose("SIP/8001-0000e7e2", "1, OK, 000, <?xml version="1.0" encoding="utf-8" ?>
    -- <result>
    --     <instance confidence="100">你好</instance>
    --     <ext>
    --  <logid>00953718d8c911ea_1_1</logid>
    --     </ext>
    -- </result>

Arsen Chaloyan

unread,
Aug 7, 2020, 9:05:25 PM8/7/20
to UniMRCP
Just to be clear, while the helper function RECOG_INSTANCE() has been available for years, this post describes an extension to this function which allows to retrieve individual fields in the <instance> element. The extension has been implemented lately, which in fact you do not seem to use or need.

Now, moving to your specific case, the way you use RECOG_INSTANCE() seems correct. The problem could be in special characters (hieroglyphs) returned with NLSML, which I have personally never used.

The following line of code would be your starting point for troubleshooting this issue.



--
You received this message because you are subscribed to the Google Groups "UniMRCP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unimrcp+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/unimrcp/29680456-12d0-41af-a6c8-c9cd3ddc6c4cn%40googlegroups.com.

sin...@gmail.com

unread,
Aug 7, 2020, 11:46:42 PM8/7/20
to UniMRCP
thanks 。 I will check it myself...
may be you are right...


[2020-08-08 11:11:15] DEBUG[30410]: speech_channel.c:109 speech_channel_set_state_unlocked: (ASR-12) PROCESSING ==> READY
[2020-08-08 11:11:15] DEBUG[4927][C-000078bd]: app_synthandrecog.c:649 recog_channel_get_results: (ASR-12) Completion-Cause: 000
[2020-08-08 11:11:15] WARNING[4927][C-000078bd]: src/apt_nlsml_doc.c:310 : Unknown child element < instance > for <result>
[2020-08-08 11:11:15] WARNING[4927][C-000078bd]: src/apt_nlsml_doc.c:310 : Unknown child element <ext> for <result>
[2020-08-08 11:11:15] WARNING[4927][C-000078bd]: src/apt_nlsml_doc.c:318 : Invalid NLSML document: at least one child element MUST be specified for <result>
[2020-08-08 11:11:15] NOTICE[4927][C-000078bd]: app_synthandrecog.c:665 recog_channel_get_results: (ASR-12) Result:

<?xml version="1.0" encoding="utf-8" ?>
<result>
    < instance confidence="100">你好</ instance  >
    <ext>
        <logid>cf58f642d92411ea_1_1</logid>
    </ext>
</result>                                                             

Arsen Chaloyan

unread,
Aug 10, 2020, 10:54:40 PM8/10/20
to UniMRCP
The received result does not actually conform to NLSML. Which MRCP server do you use?

Reply all
Reply to author
Forward
0 new messages