fresh-midnight-94038
05/08/2025, 4:17 PMtall-airline-16756
05/08/2025, 4:17 PMtall-airline-16756
05/08/2025, 4:17 PMfrom livekit import agents
from livekit.agents import AgentSession, RoomOutputOptions
from livekit.plugins import tavus # or your chosen provider
async def entrypoint(ctx: agents.JobContext):
await ctx.connect()
session = AgentSession(
# Configure your STT, LLM, TTS components
)
avatar = tavus.AvatarSession(
replica_id="...", # Provider-specific configuration
persona_id="...",
)
# Start the avatar and wait for it to join
await avatar.start(session, room=ctx.room)
# Start your agent session with audio disabled (avatar handles it)
await session.start(
room=ctx.room,
room_output_options=RoomOutputOptions(
audio_enabled=False,
),
# Other agent configuration
)
1. In your frontend: Use the useVoiceAssistant
hook to display the avatar:
const { state, audioTrack } = useVoiceAssistant();
return (
<div classname="h-80">
<barvisualizer state="{state}" barcount="{5}" trackref="{audioTrack}" style="{{}}"/>
<p classname="text-center">{state}</p>
</div>
);
1. Handle authentication: Generate a token for your application to connect to LiveKit rooms.
The avatar worker joins your LiveKit room as a separate participant to publish synchronized audio and video, creating a more engaging user experience.
Sources: Virtual avatar integrations | LiveKit Docs | Web and mobile frontends | LiveKit Docsfresh-midnight-94038
05/08/2025, 4:18 PMtall-airline-16756
05/08/2025, 4:18 PMfresh-midnight-94038
05/08/2025, 4:19 PMtall-airline-16756
05/08/2025, 4:19 PM