unispeech / asterisk-unimrcp

UniMRCP modules for Asterisk
http://www.unimrcp.org/asterisk
GNU General Public License v2.0
48 stars 35 forks source link

Does unimrcp support transcoding? #22

Closed wavestudio closed 3 years ago

wavestudio commented 6 years ago

I setup a endpoint with codec opus to establish sip connection with user side(I named A side), in dialplan i call MRCPRecog to establish mrcp connection with MRCP server(I named B side), in mrcp.conf,i set the codec to PCMA,PCMU,but i failed to audio recognize, the log is(sorry i hide the real IP information):

Executing [s@internal:2] MRCPRecog("PJSIP/1003-00000000", "builtin:grammar/default, p=default&t=50000&b=0&ct=0.7&spl=zh-CN&sw=false&rm=normal&nit=5000&sct=300") in new stack [Dec 27 15:47:03] NOTICE[22374][C-00000001]: app_mrcprecog.c:1079 app_recog_exec: MRCPRecog() grammar: builtin:grammar/default [Dec 27 15:47:03] NOTICE[22374][C-00000001]: app_mrcprecog.c:1100 app_recog_exec: MRCPRecog() options: p=default&t=50000&b=0&ct=0.7&spl=zh-CN&sw=false&rm=normal&nit=5000&sct=300

0x7f96cc010e70 -- Strict RTP learning after remote address set to: xxx.xxx.xxx.xxx:33138 0x7f96cc010e70 -- Strict RTP switching source address to xxx.xxx.xxx.xxx:33138 [Dec 27 15:47:04] NOTICE[22374][C-00000001]: src/mrcp_application.c:117 : Create MRCP Handle 0x7f96c4014058 [speech-nuance5-mrcp2] [Dec 27 15:47:04] NOTICE[22374][C-00000001]: src/mrcp_client_session.c:131 : Create Channel ASR-0 [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_client_session.c:385 : Receive App Request ASR-0 [2] [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_client.c:696 : Add MRCP Handle ASR-0 [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_client_session.c:717 : Add Control Channel ASR-0 new@speechrecog [Dec 27 15:47:04] WARNING[22358]: src/mpf_rtp_stream.c:229 : Failed to Match Codec List xxx.xxx.xxx.xxx:20001 [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_client_session.c:409 : Send Offer ASR-0 [c:1 a:1 v:0] to xxx.xxx.xxx.xxx:8010 [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_sofiasip_client_agent.c:301 : Local SDP ASR-0 v=0 o=Asterisk 0 0 IN IP4 xxx.xxx.xxx.xxx s=- c=IN IP4 xxx.xxx.xxx.xxx t=0 0 m=application 9 TCP/MRCPv2 1 a=setup:active a=connection:new a=resource:speechrecog a=cmid:1 m=audio 0 RTP/AVP 19 a=mid:1

[Dec 27 15:47:04] NOTICE[22359]: src/mrcp_sofiasip_client_agent.c:556 : Receive SIP Event [nua_i_state] Status 0 INVITE sent [speech-nuance5-mrcp2] [Dec 27 15:47:04] NOTICE[22359]: src/mrcp_sofiasip_client_agent.c:494 : SIP Call State ASR-0 [calling] [Dec 27 15:47:04] NOTICE[22359]: src/mrcp_sofiasip_client_agent.c:556 : Receive SIP Event [nua_r_invite] Status 200 OK [speech-nuance5-mrcp2] [Dec 27 15:47:04] NOTICE[22359]: src/mrcp_sofiasip_client_agent.c:556 : Receive SIP Event [nua_i_state] Status 200 OK [speech-nuance5-mrcp2] [Dec 27 15:47:04] NOTICE[22359]: src/mrcp_sofiasip_client_agent.c:494 : SIP Call State ASR-0 [ready] [Dec 27 15:47:04] NOTICE[22359]: src/mrcp_sofiasip_client_agent.c:380 : Remote SDP ASR-0 v=0 o=UniMRCPServer 8852379940481215765 6244095247722662515 IN IP4 xxx.xxx.xxx.xxx s=- c=IN IP4 xxx.xxx.xxx.xxx t=0 0 m=application 2544 TCP/MRCPv2 1 a=setup:passive a=connection:new a=channel:99cef90c163f407f@speechrecog a=cmid:1 m=audio 0 RTP/AVP 19

[Dec 27 15:47:04] NOTICE[22359]: src/mrcp_sofiasip_client_agent.c:556 : Receive SIP Event [nua_i_active] Status 200 Call active [speech-nuance5-mrcp2] [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_client_session.c:149 : Receive Answer ASR-0 [c:1 a:1 v:0] Status 200 [Dec 27 15:47:04] NOTICE[22357]: src/mrcp_client_connection.c:336 : Established TCP/MRCPv2 Connection xxx.xxx.xxx.xxx:44750 <-> xxx.xxx.xxx.xxx:2544 [Dec 27 15:47:04] NOTICE[22357]: src/mrcp_client_connection.c:433 : Add Control Channel 99cef90c163f407f@speechrecog xxx.xxx.xxx.xxx:44750 <-> xxx.xxx.xxx.xxx:2544 [1] [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_client_session.c:453 : Raise App Response ASR-0 <99cef90c163f407f> [2] SUCCESS [0] [Dec 27 15:47:04] ERROR[22356]: app_mrcprecog.c:258 speech_on_channel_add: (ASR-0) Unable to determine codec descriptor [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_client_session.c:385 : Receive App Request ASR-0 <99cef90c163f407f> [1] [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_client_session.c:828 : Terminate Session ASR-0 <99cef90c163f407f> [Dec 27 15:47:04] NOTICE[22357]: src/mrcp_client_connection.c:457 : Remove Control Channel 99cef90c163f407f@speechrecog [0] [Dec 27 15:47:04] NOTICE[22357]: src/mrcp_client_connection.c:384 : Close TCP/MRCPv2 Connection xxx.xxx.xxx.xxx:44750 <-> xxx.xxx.xxx.xxx:2544 [Dec 27 15:47:04] NOTICE[22359]: src/mrcp_sofiasip_client_agent.c:556 : Receive SIP Event [nua_r_bye] Status 200 OK [speech-nuance5-mrcp2] [Dec 27 15:47:04] NOTICE[22359]: src/mrcp_sofiasip_client_agent.c:556 : Receive SIP Event [nua_i_state] Status 200 to BYE [speech-nuance5-mrcp2] [Dec 27 15:47:04] NOTICE[22359]: src/mrcp_sofiasip_client_agent.c:494 : SIP Call State ASR-0 [terminated] [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_client_session.c:207 : Session Terminated ASR-0 <99cef90c163f407f> [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_client_connection.c:233 : Destroy TCP/MRCPv2 Connection xxx.xxx.xxx.xxx:44750 <-> xxx.xxx.xxx.xxx:2544 [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_client.c:706 : Remove MRCP Handle ASR-0 <99cef90c163f407f> [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_client_session.c:453 : Raise App Response ASR-0 <99cef90c163f407f> [1] SUCCESS [0] [Dec 27 15:47:04] NOTICE[22356]: src/mrcp_application.c:203 : Destroy MRCP Handle ASR-0 [Dec 27 15:47:04] NOTICE[22374][C-00000001]: app_mrcprecog.c:1040 mrcprecog_exit: MRCPRecog() exiting status: ERROR on PJSIP/1003-00000000 == Spawn extension (internal, s, 2) exited non-zero on 'PJSIP/1003-00000000'

if i change the codec of A side from "opus" to "ulaw,alaw", the audio recognize functionity works fine. Does unimrcp support transcoding?And how should i do?

achaloyan commented 6 years ago

The UniMRCP client library supports PCMU/A and linear PCM only. However, Asterisk/UniMRCP should be capable of encoding/decoding opus to PCM. The problem could be in the sampling rate. If you are using 16 kHz, then make sure mrcp.conf contains 16kHz equivalents as well. Otherwise, intersection of capabilities will result in no selected codec. Also what versions of Asterisk and UniMRCP are you using?

wavestudio commented 6 years ago

@achaloyan The version of Asterisk is 14.6.2, and the version of UniMRCP is 1.5.0. Codec setting in my mrcp.conf is "codecs = PCMU PCMA L16/96/8000 telephone-event/101/8000".

achaloyan commented 6 years ago

The provided configuration is for the MRCP leg which matters but partially. I see your calls are coming through PJSIP. So, what are the codecs used in this leg. Also, pay attention to the sampling rate. If you have 16 kHz in the incoming SIP call, then you should have 16 kHz codecs specified in mrcp.conf as well.

ThroughLee commented 5 years ago

@wavestudio So did you fix the problem? I'm facing the same problem.

michelepra commented 4 years ago

from @achaloyan response the answer of this issue is NO. Both call leg must use same codec. UniMRCP client library supports PCMU/A and linear PCM, so other peer must use PCMU/A or LPCM.

From testing i see that the codec configuration in mrcp.conf is only to filter, not for transcoding. The problem is when inbound call not use one of this codec. and in dialplan or agi is called mrcp.

Example 1.

  1. user A offer (alaw, opus) -> asterisk answer (alaw, opus) [codec selected alaw]
  2. agi call to mrcp [OK - codec in inviate is alaw, so rtp in alaw in two leg]

Example 2.

  1. user A offer (opus, alaw) -> asterisk answer (opus, alaw) [codec selected opus]
  2. agi call to mrcp [FAIL - invite from asterisk to mrcp has no codec because opus don't match with codecs configured in mrcp.conf]

There's also another example that fail, but i think asterisk is buggy in this situation

  1. user A offer (opus, alaw) -> asterisk (opus, alaw) force answer to use (alaw) [codec selected alaw]
  2. agi call to mrcp [FAIL - codec in invite is alaw, rtp from asterisk to mrcp server is marked as alaw but rtp captured with tcpdump is incomprehensible, like noise (maybe is opus)]
achaloyan commented 3 years ago

This problem must have been fixed in asterisk-unimrcp-1.8.0 with this commit in particular.