How do i integrate livekit avatar to frontend
# ask-ai
m
How do i integrate livekit avatar to frontend
t
Thanks for reaching out, AI. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I can help with that. You’re asking how to integrate a LiveKit avatar into your frontend; I’ll walk you through the general approach and can provide code specific to your stack once you tell me which frontend framework and avatar provider you’re using. Quick summary of how avatars work (what you need to render) • The avatar is published by a separate participant called the avatar worker (participant kind = Agent) that joins the room when an AvatarSession starts. • The avatar worker has an attribute
lk.publish_on_behalf
set to the agent’s identity — use this to identify the avatar worker. • Render the avatar’s audio and video tracks (from the avatar worker), not the agent participant’s tracks. If you want the short integration checklist 1. Identify the avatar worker in the room: ◦ Find the agent participant (agent identity with no
lk.publish_on_behalf
), then find the participant where
lk.publish_on_behalf === agent.identity
. 1. Get the avatar worker’s audio and video tracks. 2. Attach the video track to a DOM/video component and the audio track to an audio element (or let the SDK handle playback). 3. Optionally: use the provided React helper
useVoiceAssistant
which already finds the avatar worker and returns
agent
,
audioTrack
, and
videoTrack
. What I need from you to give exact code • Frontend framework / platform (choose one): React (web), Vue, Angular, React Native, Flutter, SwiftUI, Android, or plain JS. • Are you using any LiveKit helper components or the plain LiveKit client SDK? • Which avatar provider/plugin are you using (examples: Anam, Tavus, Hedra)? Do you already have the AvatarSession set up on the backend? If you want a React example right away • I can provide a minimal React snippet showing how to: a. Find the avatar worker via participant attributes. b. Attach the
VideoTrack
to a <video> element (or LiveKit React components). Tell me if you prefer that and which UI approach you use (plain DOM elements vs. LiveKit React components). If you want links or starter apps • I can point you to example starter apps (Next.js, React Native, Flutter, SwiftUI, Android) that already handle avatar rendering. Which option would you like me to show next? (Pick one) • A minimal plain-React + LiveKit client snippet • A
useVoiceAssistant
-based React example • A Vue/Angular/plain-JS example • Mobile example (React Native / Flutter / native) Sources: Virtual avatar models overview | LiveKit Documentation | Anam virtual avatar integration guide | LiveKit Documentation
m
Are there documenation that i can refer
t
Thanks — I can point you to the most relevant documentation and example projects for integrating a LiveKit avatar into your frontend. Primary docs and guides • LiveKit Voice Agents / Avatar guide (overview and architecture): https://docs.livekit.io/agents/voice-agents • Avatar worker / publish-on-behalf explanation (how avatar workers publish tracks): https://docs.livekit.io/agents/avatar-workers SDK & component references • LiveKit Web SDK (connect, participants, tracks, rendering): https://docs.livekit.io/client-sdk/web • LiveKit React components & hooks (includes
useVoiceAssistant
and other helpers): https://docs.livekit.io/components/react Avatar plugin & provider setup • Anam avatar plugin setup (example plugin used for generated avatars): https://github.com/livekit-examples/agents-plugin-anam • Agent plugins overview and configuration: https://docs.livekit.io/agents/plugins Starter apps with avatar support (examples you can clone) • Next.js Voice Agent (web React starter): https://github.com/livekit-examples/agent-starter-react • React Native Voice Agent: https://github.com/livekit-examples/agent-starter-react-native • Flutter Voice Agent: https://github.com/livekit-examples/agent-starter-flutter • SwiftUI Voice Agent: https://github.com/livekit-examples/agent-starter-swift • Android Voice Agent: https://github.com/livekit-examples/agent-starter-android Quick pointers to the exact parts you’ll likely use • Finding the avatar worker in the room (look for
lk.publish_on_behalf
attribute on a participant): see the avatar worker guide above. • Rendering tracks from the avatar worker (use Web SDK or React components to attach `VideoTrack`/`AudioTrack` to UI elements): see the Web SDK and React components docs. • Example code that already handles this: refer to the Next.js Voice Agent starter repo. Would you like a short curated snippet or a specific doc link for your framework (React, Vue, Flutter, etc.)? Tell me which framework and I’ll point to the exact page or code sample.