How do I set a static image as the avatar of the a...
# ask-ai
c
How do I set a static image as the avatar of the agent in a livekit room?
t
Thanks for reaching out, Benjamin. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To set a static image as the avatar of the agent in a LiveKit room, follow these steps: 1. Prepare the Avatar Image: Ensure you have a static image (PNG, JPG, or JPEG) named
avatar.png
,
avatar.jpg
, or
avatar.jpeg
in the same directory as your agent script. 2. Import Required Libraries: Include the necessary imports in your Python script:
Copy code
from PIL import Image
import os
from livekit.plugins import hedra
3. Load the Avatar Image: Use the following code to load the image:
Copy code
avatar_dir = os.path.dirname(os.path.abspath(__file__))
avatar_image = None

for ext in ['.png', '.jpg', '.jpeg']:
    image_path = os.path.join(avatar_dir, f'avatar{ext}')
    if os.path.exists(image_path):
        avatar_image = Image.open(image_path)
        break

if not avatar_image:
    raise FileNotFoundError("No avatar image found. Please place an avatar.png, avatar.jpg, or avatar.jpeg in the directory.")
4. Create the Avatar Session: Initialize the session with your static image:
Copy code
avatar_session = hedra.AvatarSession(
    avatar_participant_identity="static-avatar",
    avatar_image=avatar_image,
)
5. Start the Avatar Session: Start the session within the LiveKit room:
await avatar_session.start(session, room=job_context.room)
This will display the static image as the avatar in the LiveKit room. Let me know if you need further assistance!
i
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!