how do i update a hedra avatar with a new image wh...
# ask-ai
c
how do i update a hedra avatar with a new image when it is already intialized?
t
Thanks for reaching out, Bryce. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to update a Hedra avatar with a new image after it’s already up and running, you’ll need to create a brand-new
AvatarSession
with your updated image and start it fresh. Just a heads-up: the Hedra integration doesn’t support changing the avatar image on the fly within the same session. Here’s a simple way to do it: 1. If needed, remove the existing avatar participant first to avoid any conflicts. You can do this using the LiveKit API by removing the participant by their identity. 2. Create a new
AvatarSession
by using the
hedra.AvatarSession
class and pass in your new image through the
avatar_image
parameter (which should be a PIL
Image
object). 3. Start this new avatar session with your agent session and room. Here’s a quick example:
Copy code
from PIL import Image
from livekit.plugins import hedra

# Load your new image
new_image = Image.open("/path/to/new_avatar.jpg")

# Create a new avatar session with the updated image
new_avatar = hedra.AvatarSession(
    avatar_image=new_image,
    avatar_participant_identity="hedra-avatar-agent"  # You can use the same identity or a new one
)

# Start the new avatar session
await new_avatar.start(session, room=ctx.room)
Just remember, once you’ve created an
AvatarSession
, you can’t tweak it directly. To update the image, you’ll need to start a new session like this. And if you’re working with a frontend, don’t forget you might need to refresh the participant list or listen for updates so the change shows up smoothly. Sources: Hedra virtual avatar integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-hedra/README.md | complex-agents/role-playing/role_playing_frontend/components/character-port...