Zeli AvatarDeveloper docs
v0.1.0

Resources / Examples

Examples

Complete, runnable programs for the common tasks. These mirror the scripts in the SDK's examples/ directory (quickstart.py, save_video.py, talk_stream.py).

Set your server URL once, then run any example:

export ZELI_SERVER_URL=http://your-server:8080
export ZELI_AVATAR_ID=presenter-male-1080   # optional

Quickstart — chat and print the transcript

Mirrors examples/quickstart.py.

import asyncio, os
from zeli import AvatarConfig, ClientOptions, Message, ZeliClient, ZeliEvent
 
client = ZeliClient(
    avatar_config=AvatarConfig(avatar_id=os.environ.get("ZELI_AVATAR_ID")),
    options=ClientOptions(server_url=os.environ["ZELI_SERVER_URL"]),
)
 
@client.on(ZeliEvent.MESSAGE_RECEIVED)
async def _msg(m: Message):
    print(f"{m.role.value}: {m.content}")
 
async def main():
    async with client.connect() as session:
        await session.send_message("Hi! Introduce yourself in one sentence.")
        await asyncio.sleep(12)
 
asyncio.run(main())

Save a clip to disk

Mirrors examples/save_video.py. Requires the display extra (pip install "zeli-avatar[display]").

import asyncio, os, cv2, numpy as np
from zeli import AvatarConfig, ClientOptions, ZeliClient
 
client = ZeliClient(
    avatar_config=AvatarConfig(avatar_id=os.environ.get("ZELI_AVATAR_ID")),
    options=ClientOptions(server_url=os.environ["ZELI_SERVER_URL"]),
)
 
async def main():
    async with client.connect() as session:
        await session.talk("Recording a short sample of the Zeli avatar now.")
        writer, deadline = None, asyncio.get_event_loop().time() + 8
        async for frame in session.video_frames():
            img = frame.to_ndarray(format="bgr24")
            if writer is None:
                h, w = img.shape[:2]
                writer = cv2.VideoWriter("avatar_clip.mp4", cv2.VideoWriter_fourcc(*"mp4v"), 25.0, (w, h))
            writer.write(img.astype(np.uint8))
            if asyncio.get_event_loop().time() >= deadline:
                break
        if writer:
            writer.release()
 
asyncio.run(main())

Stream text incrementally

Mirrors examples/talk_stream.py.

import asyncio, os
from zeli import AvatarConfig, ClientOptions, ZeliClient
 
client = ZeliClient(
    avatar_config=AvatarConfig(avatar_id=os.environ.get("ZELI_AVATAR_ID")),
    options=ClientOptions(server_url=os.environ["ZELI_SERVER_URL"]),
)
 
async def main():
    async with client.connect() as session:
        async with session.create_talk_stream() as talk:
            for chunk in ["Thanks for trying Zeli. ", "This audio is being ",
                          "streamed one piece ", "at a time."]:
                await talk.send(chunk)
                await asyncio.sleep(0.2)
            await talk.send("", end_of_speech=True)
        await asyncio.sleep(8)
 
asyncio.run(main())

talk and talk streams require the server's control gateway. If a box runs without it, use send_message — see Driving the avatar.

Zeli Avatar · real-time avatars over WebRTC · self-hostable · AU data residency · source