Hi, I’m having serious slowness issues using Hedra...
# ask-ai
p
Hi, I’m having serious slowness issues using Hedra avatar, and creating pre-synthesized audio to pass to it like this: say_handle = session.say(text=“”, audio=frame_stream(), add_to_chat_ctx=False, allow_interruptions=False) However, from the time an audio chunk is yielded to that stream to the time it is actually played, it’s taking 4-5 seconds. Is this normal for pre-synthesized scenario? Any tips on how to reduce that? Is it related to turn detection? Do I need to manually override that?
t
Thanks for reaching out, Ali. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I totally get how frustrating it can be when Hedra avatar and pre-synthesized audio feel slow. Here are some helpful tips to speed things up: • Pre-synthesized Audio: When you use
session.say()
with pre-synthesized audio, it should help cut down response time since it skips the TTS step. Just double-check that the
audio
parameter is correctly passed as an
AsyncIterable[rtc.AudioFrame]
. • Turn Detection: Turn detection might add some delay. You can tweak settings like
min_endpointing_delay
(which defaults to 500ms) to get better timing. Also, turning on
preemptive_generation
in your
AgentSession
can help reduce latency by overlapping model inference with the user’s audio. • Direct Room Publishing: For avatars, make sure the generation server joins the same room as a participant and publishes synchronized audio and video directly. This avoids extra encoding and transmission delays. If you want to dive deeper, checking out Hedra’s docs on the
frame_stream
API and latency might be really helpful. And hey, if you share more about your setup or how things are configured, I’d be happy to help you troubleshoot more specifically! Sources: Bringing AI avatars to voice agents | livekit-agents/livekit/agents/voice/agent_session.py | Agent speech and audio | LiveKit Docs | Agent Testing & Evaluation | livekit/livekit_composite | DeepWiki | Virtual avatar integrations | LiveKit Docs
p
What if I don't need turn detection and when I call say I want things to generate right away?
t
If you’d prefer to skip turn detection and have the audio start playing right away when you call
say
, you can easily set that up! Here’s a quick way to do it: • Set
preemptive_generation=True
in your
AgentSession
. This makes sure the system begins inference and TTS requests as soon as it gets the user transcript, without waiting for a turn to finish. • Turn off turn detection by adjusting the session to avoid endpointing delays. For example, setting
min_endpointing_delay=0
and
max_endpointing_delay=0
removes those waiting times. Doing this should help cut down latency and get your audio generated right away. If you want a hand setting this up or have any questions, just let me know—I’m here to help!
p
Even with those changes, I’m seeing 3-4 seconds latency from the time audio is yielded to session.say to the time audio is heard.
t
Hey there! To help with that 3-4 second delay you're seeing, here are some friendly tips and tweaks you can try out: • Infrastructure: If you're on AWS burstable instances like t3 or t4, consider switching to steady, non-burstable ones like
m5
,
c5
, or
c6i
. This can help avoid CPU throttling, which often causes those annoying delays. • Audio Frame Optimization: Make sure your
AsyncIterable[rtc.AudioFrame]
is set up to minimize buffering and streaming lag. If you can, try pre-loading audio frames to keep things smooth. • Network Proximity: Bringing your agent and services closer together on the network can really cut down on transmission time. • Monitoring: Keep an eye on metrics like Time To First Byte (TTFB) and audio playback latency to spot where things might be slowing down. Ideally, latency should stay under 500ms for the best experience. Could you tell me a bit more about your setup? Like the instance type, network details, and how you’re generating and streaming your pre-synthesized audio? That way, I can help zero in on the issue and offer some spot-on advice. Sources: examples/voice_agents/realtime_turn_detector.py | Agent speech and audio | LiveKit Docs | Gemini Live API integration guide | LiveKit Docs | Turn detection and interruptions | LiveKit Docs | Troubleshooting Latency and Timeout Errors with Turn Detection on AWS
p
would it help if I go with manual turn detection?
t
Switching to manual turn detection can be a great way to cut down on delays caused by automatic turn detection. With manual turn detection, you get to decide exactly when turns start and end, which helps speed things up by skipping those endpointing delays and other automated steps. Here’s how you can set up manual turn detection in your session:
Copy code
session = AgentSession(
    turn_detection="manual",
    # ... other configurations
)
This way, no automatic turn detection will get in the way, and audio generation will kick off right away when you call
say
. If you want, I’m here to help you with this setup or answer any other questions you might have!
p
will I need to call other session functions when I set manual as well?
t
Yes, when you’re using manual turn detection, you’ll want to manage the flow of turns yourself by calling a couple of session functions. Here’s how it works: • Start a Turn: Just use
session.start_turn()
to let the system know a turn is beginning. • End a Turn: Then, use
session.end_turn()
to mark when the turn is over. These functions give you the flexibility to decide exactly when the system listens and responds, so you’re in full control of the conversation flow. If you’d like, I’m here to help you set this up or answer any questions along the way!
p
end_turn would be called when agent response is to be played?
t
Yes, when you're using manual turn detection, you’ll want to call
end_turn()
right after the agent’s response is ready to go. This lets the system know the agent’s turn is over and it can switch back to listening for what the user says next or get ready for the next step. If you have any questions or want me to walk you through it, just let me know—I’m happy to help!