Hello, I'm working on an agent connected to Twilio...
# telephony
p
Hello, I'm working on an agent connected to Twilio using inbound/outbound trunks. I have my livekit server running on an instance in frankfurt, which relies on livekit cloud. I have configured twilio so: • origination SIP URI:
sip:********.eu.sip.livekit.cloud;edge=frankfurt
• Twilio Elastic SIP is on Ireland On livekit side: • Outbound SIP URI:
***********.pstn.frankfurt.twilio.com
It works fine, but from my measurements, considering the time that passes between the speaker finished speaking and the agent starts answering, it takes ~0.94s extra time. Do you know what else can I do? As a sanity check, by using other endpoints like dublin or even ashburn (USA), there is some difference, but not that much, so I'm starting to think the problem is not in network latency. I have some suspects: • Network latency • Maybe it is some time twilio takes to convert phone conversation into something it can sends through SIP? • Or even it is on livekit cloud side, considering the time it takes to convert from whatever comes from SIP to WebRTC? Am I right about the last two? Is there any way I can play with these so i can, for instance, reduce the amount of data to be sent by reducing quality? Also, would you recommend the other providers in the documentation (Telnyx or Pilvo)? Sorry for so many questions, main question reduces to: somebody knows how can i reduce this extra time? Thanks in advance.
➕ 1
r
I think best bet is to start by looking at the agent metrics to see the TTFT, TTFB etc.
p
hi, thanks for your answer. Actually i've been already looking at these in the past. i was able to reduce these ttft, ttfb, etc values as much as i could. After some tests, using livekit with the playground the conversation is quite smooth and there is some delay, but nothing with a high impact in the user experience. However, my question was not about optimizing the delay INSIDE livekit, but the external delay introduced by the integration with Twilio. i did my experiments as follow: • I added a log that measures the end-to-end time as the time passing between the user passed from speaking->listening until the agent passed from listening->speaking. I know this can introduce some small delay, but serves as an intuition, and with the playground seems reasonable ◦ Of course, this measures end-to-end as seen by livekit, not by the final user since it doesn't take into account the delay produced by the browser via webrtc nor the additional delay introduced by twilio. Just the end to end delay as seen internally by the server. • Then I initiated a call using twilio. I recorded the call, and checked the logs for this end-to-end time. I can see that the end-to-end time remains equivalent. However, checking the recorded audio I measure the actual delay as perceived by the user. On average, it is ~0.94s longer than the one i'm measuring inside the server. In other words, the integration with twilio adds too much delay. This additional delay is much smaller when using the playground. Does anybody know how to reduce this extra time introduced by the integration by Twilio? Does any have different experiences with the different providers integrated in Livekit?
➕ 1
i
@polite-microphone-49233 I'm also facing the exact same issue. I have livekit deployed in Azure - US Central. I tried making calls (Inbound) from US and India. In both the scenarios there is a overhead of 0.9-0.95 sec. I have analyzed the breakdown of it. Latency overhead between livekit and twilio is around 0.2 sec, between twilio and user is around 0.65 - 0.75 sec. @refined-appointment-81829 Any idea how can we reduce this? Thanks in advance.
r
Have you tried different models, llm, and tts to see if you get better performance? Hosting in US Central is probably a great start. How does it look if you use webRTC only as a comparison with SIP? How do you determine the delay for the SIP leg?
b
@refined-appointment-81829 Isn't it better to host in US East near Virginia ? According to ChatGPT thats where OpenAI hosts their models. Not sure if you know something more that I dont.
r
Generally speaking you will want to host (in terms of network latency) as close as possible to your LLM, STT, and TTS to get optimal performance.
i
I had recordings of a call at livekit, twilio and at end user. As per recording of livekit, the agent response time is around 1.5 sec - 1.6 sec, But as per recording at twilio 1.7-18 sec (200 ms overhead). recording at end user around 2.5 sec (950 ms overhead). even though as per livekit recording the agent response time is good enough, it not good as compared to user perceived latency. I want to optimize this overhead coming outside livekit. I'm majorly concerned about response time difference between twilio recording and end user recording. @refined-appointment-81829 Please let me know if you have any inputs regarding this issue. This is a high priority issue for us to go live.
p
Just to confirm, I have a similar situation as described by @icy-cpu-74166. I optimized my deployments so everything was as close as possible (in fact we are using some azure based deployments). Main difference comes between using the same service through web and phone. I've even configured the closest edges using the information provided here and here, but although i notice differences (as a sanity check, i even tried going through tokyo just to see if the overhead increased), most of the overhead seems to come from other source. I'm not familiar with what happens internally, but are there chances that problems could be related with audio reencoding from phone to some sip-compatible format, or even on livekit cloud side converting from sip-compatible to webrtc-compatible audio format? Would it be possible in that case to work at a lower sample-rate so at least we can move a smaller amount of data? in the end, most of asr work at 16kHz (just trying to guess other alternatives, not saying this is the root of the problem since i cant access the internals)