How to use static avatar?
# ask-ai
i
How to use static avatar?
t
Thanks for reaching out, Jan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To use a static avatar in LiveKit, you can integrate it using the Hedra plugin, which supports static images. Here are the steps: 1. Install the Hedra plugin:
pip install "livekit-agents[hedra]~=1.0"
2. Set up your Hedra API key: Create a
.env
file and add:
HEDRA_API_KEY=your_hedra_api_key
3. Place your avatar image: Name your avatar image
avatar.png
,
avatar.jpg
, or
avatar.jpeg
and place it in the same directory as your agent script. 4. Load the avatar image in your agent script:
Copy code
from PIL import Image
import os

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 avatars directory.")
5. Create and start the avatar session:
Copy code
from livekit.plugins import hedra

avatar_session = hedra.AvatarSession(
    avatar_image=avatar_image,
)

await avatar_session.start(
    session,  # Your AgentSession instance
    room=ctx.room,
)
Let me know if you need further assistance with the implementation!
i
What if I don't want to use third-party API? I want to just simply stream an avatar locally
t
Just to make sure I’m on the right track—are you hoping to stream a static avatar using only LiveKit’s built-in features, without any extra plugins or integrations? I want to make sure I give you the best advice possible!
i
exactly!x
t
Just a heads-up—LiveKit doesn’t natively support streaming static avatars on its own; usually, this kind of feature comes through third-party plugins or integrations like Hedra. If you have a particular idea in mind or want to explore some other ways to make it work, feel free to share! I’m here to help you find the best solution. Sources: livekit-plugins/livekit-plugins-simli/livekit/plugins/simli/avatar.py | Virtual avatar integrations | LiveKit Docs | avatars/hedra/README.md