OpenSIPS / opensips-ai-voice-connector-ce

OpenSIPS AI Voice Connector Community Edition Platform
GNU General Public License v3.0
15 stars 4 forks source link

The call connects, but media IP in SDP is 127.0.0.1 and some API errors #2

Open shah-hussain-khattak opened 1 month ago

shah-hussain-khattak commented 1 month ago

Hi Team,

Thanks for the help in issue # 1, I can connect the call. But seeing the media IP negotiated by the server is 127.0.0.1 in the final 200 SDP:

200 OK SDP from Server:

SIP/2.0 200 OK Via: SIP/2.0/UDP 218.33.x.x:65057;received=218.33.x.x;rport=65057;branch=z9hG4bKPj6c11ceb13f0544ed97ad05cba919a261 To: sip:openai@domain.sip;tag=B2B.97.456.1730413641.425227748 From: sip:shah@domain.sip;tag=e7f3a84ad406418da5e593977bfce5e2 Call-ID: 3f38287e99fb4608b5301996723725ab CSeq: 28638 INVITE Content-Type: application/sdp Contact: Server: OpenSIPS (3.6.0-dev (x86_64/linux)) Content-Length: 187

v=0 o=- 3939438443 3939438443 IN IP4 127.0.1.1 s=pjmedia t=0 0 m=audio 42738 RTP/AVP 8 c=IN IP4 127.0.0.1 a=sendrecv a=ssrc:401287346 cname:2a432bed342839bf a=rtpmap:8 PCMA/8000

From container logs:

2024-10-31 22:27:22,690 - INFO - handling B2B.97.456.1730413641.425227748 using openai AI 2024-10-31 22:27:22,691 - ERROR - Task exception was never retrieved future: <Task finished name='Task-8' coro=<Call.send_rtp() done, defined at /app/src/call.py:120> exception=OSError(22, 'Invalid argument')> Traceback (most recent call last): File "/app/src/call.py", line 153, in send_rtp self.serversock.sendto(bytes.fromhex(rtp_packet), OSError: [Errno 22] Invalid argument 2024-10-31 22:27:23,716 - ERROR - Task exception was never retrieved future: <Task finished name='Task-7' coro=<OpenAI.start() done, defined at /app/src/openai_api.py:67> exception=ConnectionClosedError(Close(code=3003, reason='invalid_request_error.access_not_enabled'), Close(code=3003, reason='invalid_request_error.access_not_enabled'), True)> Traceback (most recent call last): File "/app/src/openai_api.py", line 81, in start await self.ws.send(json.dumps({"type": "session.update", File "/usr/local/lib/python3.10/site-packages/websockets/asyncio/connection.py", line 403, in send async with self.send_context(): File "/usr/local/lib/python3.10/contextlib.py", line 199, in aenter return await anext(self.gen) File "/usr/local/lib/python3.10/site-packages/websockets/asyncio/connection.py", line 873, in send_context raise self.protocol.close_exc from original_exc websockets.exceptions.ConnectionClosedError: received 3003 (registered) invalid_request_error.access_not_enabled; then sent 3003 (registered) invalid_request_error.access_not_enabled 2024-10-31 22:27:26,182 - INFO - Call B2B.97.456.1730413641.425227748 closing

2024-10-31 22:28:20,825 - INFO - handling B2B.92.226.1730413699.680774186 using deepgram AI 2024-10-31 22:28:20,844 - ERROR - Task exception was never retrieved future: <Task finished name='Task-12' coro=<Call.send_rtp() done, defined at /app/src/call.py:120> exception=OSError(22, 'Invalid argument')> Traceback (most recent call last): File "/app/src/call.py", line 153, in send_rtp self.serversock.sendto(bytes.fromhex(rtp_packet), OSError: [Errno 22] Invalid argument 2024-10-31 22:28:27,080 - INFO - Call B2B.92.226.1730413699.680774186 closing

I made some changes in the call.py script, so the media IP stays my server's public IP, the results after that were:

200 OK SDP from Server:

SIP/2.0 100 Giving it a try Via: SIP/2.0/UDP 218.33.x.x:65057;received=218.33.x.x;rport=65057;branch=z9hG4bKPjd386ff32eca042b496ef26b7192217fd To: sip:openai@domain.sip From: sip:shah@domain.sip;tag=a3cd743926c449ae82c94a2696dd8c32 Call-ID: 39bf5359a1504a62bff24c13ca7aec47 CSeq: 5819 INVITE Server: OpenSIPS (3.6.0-dev (x86_64/linux)) Content-Length: 0

SIP/2.0 200 OK Via: SIP/2.0/UDP 218.33.x.x:65057;received=218.33.x.x;rport=65057;branch=z9hG4bKPjd386ff32eca042b496ef26b7192217fd To: sip:openai@domain.sip;tag=B2B.139.188.1730414032.226335194 From: sip:shah@domain.sip;tag=a3cd743926c449ae82c94a2696dd8c32 Call-ID: 39bf5359a1504a62bff24c13ca7aec47 CSeq: 5819 INVITE Content-Type: application/sdp Contact: Server: OpenSIPS (3.6.0-dev (x86_64/linux)) Content-Length: 193

v=0 o=- 3939438833 3939438833 IN IP4 52.65.x.x s=pjmedia t=0 0 m=audio 33337 RTP/AVP 8 c=IN IP4 52.65.x.x a=sendrecv a=ssrc:240060329 cname:67012b835e406231 a=rtpmap:8 PCMA/8000

From container logs:

2024-10-31 22:33:52,486 - INFO - handling B2B.139.188.1730414032.226335194 using openai AI 2024-10-31 22:33:52,488 - ERROR - Task exception was never retrieved future: <Task finished name='Task-4' coro=<Call.send_rtp() done, defined at /app/src/call.py:100> exception=OSError(22, 'Invalid argument')> Traceback (most recent call last): File "/app/src/call.py", line 133, in send_rtp self.serversock.sendto(bytes.fromhex(rtp_packet), OSError: [Errno 22] Invalid argument 2024-10-31 22:33:53,397 - ERROR - Task exception was never retrieved future: <Task finished name='Task-3' coro=<OpenAI.start() done, defined at /app/src/openai_api.py:67> exception=ConnectionClosedError(Close(code=3003, reason='invalid_request_error.access_not_enabled'), Close(code=3003, reason='invalid_request_error.access_not_enabled'), True)> Traceback (most recent call last): File "/app/src/openai_api.py", line 81, in start await self.ws.send(json.dumps({"type": "session.update", File "/usr/local/lib/python3.10/site-packages/websockets/asyncio/connection.py", line 403, in send async with self.send_context(): File "/usr/local/lib/python3.10/contextlib.py", line 199, in aenter return await anext(self.gen) File "/usr/local/lib/python3.10/site-packages/websockets/asyncio/connection.py", line 873, in send_context raise self.protocol.close_exc from original_exc websockets.exceptions.ConnectionClosedError: received 3003 (registered) invalid_request_error.access_not_enabled; then sent 3003 (registered) invalid_request_error.access_not_enabled 2024-10-31 22:33:57,566 - INFO - Call B2B.139.188.1730414032.226335194 closing

2024-10-31 22:34:05,809 - INFO - handling B2B.398.253.1730414044.550927147 using deepgram AI 2024-10-31 22:34:05,811 - ERROR - Task exception was never retrieved future: <Task finished name='Task-8' coro=<Call.send_rtp() done, defined at /app/src/call.py:100> exception=OSError(22, 'Invalid argument')> Traceback (most recent call last): File "/app/src/call.py", line 133, in send_rtp self.serversock.sendto(bytes.fromhex(rtp_packet), OSError: [Errno 22] Invalid argument 2024-10-31 22:34:09,881 - INFO - Call B2B.398.253.1730414044.550927147 closing

Can you please share some suggestions/ideas on how to fix this? Am I missing something from the configuration point of view?

Thank you!

Regards, Shah Hussain

razvancrainea commented 1 month ago

You should not have to modify the code, you can simply set the IP in the SDP through the rtp_ip setting. If you do it like so, does it have the same behavior?

shah-hussain-khattak commented 1 month ago

Hi Razvan,

I set up the parameters as you mentioned, but for some reason, the SDP is sending 127.0.0.1 IP for media:

These are my settings:

root@ip-172-16-8-193:/usr/src/opensips-ai-voice-connector-ce/docker# more config.ini [opensips] ip = 127.0.0.1 port = 8080

[engine] event_ip = 127.0.0.1 rtp_ip=52.65.xx.xx

[deepgram] disabled = false

[openai] disabled = false

root@ip-172-16-8-193:/usr/src/opensips-ai-voice-connector-ce/docker# more .env DEEPGRAM_API_KEY= OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx MI_IP=127.0.0.1 MI_PORT=8080 root@ip-172-16-8-193:/usr/src/opensips-ai-voice-connector-ce/docker#

root@ip-172-16-8-193:/usr/src/opensips-ai-voice-connector-ce/docker# more docker-compose.yml services: engine: container_name: ai-voice-connector-engine build: context: ../ dockerfile: ./docker/Dockerfile network_mode: host environment: CONFIG_FILE: config.ini env_file:

The SDP sent is:

v=0 o=- 3939530862 3939530862 IN IP4 127.0.1.1 s=pjmedia t=0 0 m=audio 46990 RTP/AVP 8 c=IN IP4 127.0.1.1 a=sendrecv a=ssrc:2053979861 cname:4fbb0d8b65557ff9 a=rtpmap:8 PCMA/8000

Please advise me, on what I am missing.

Thank you!

razvancrainea commented 4 weeks ago

For some reason, the config file is not picked up by the engine. There was a fix for this, can you pull the latest source code? If not, try to export the RTP_IP variable in your environment.