Skip to main content
The talking avatar serves AURA as a face that joins a LiveKit room. Its source is examples/talking-avatar/aura-model in the Reactor cookbook, and the code below is simplified from it.

Files

aura-model/
The runtime drives AuraAvatar, the model class. Most of its code is in AvatarApp, which it subclasses: the room protocol and the render loop, for any model that renders a chunk of video from a chunk of speech. AuraAvatar only builds that model, AuraModel, which runs AURA’s own code and imports nothing from Reactor. Model Structure describes this split.

Contract

The contract declares the tracks and the messages that the room sees:
avatar_app.py (simplified)
  • Tracks: agent_audio takes the agent’s speech in. main_video and main_audio send the avatar out.
  • Messages: playback_started and playback_finished tell the agent what played. avatar_failed tells the client that the model failed during the session.
The app also declares 3 commands with @event: set_avatar, clear_buffer, and user_speaking_state.

How the room reaches the model

In the room, the avatar uses LiveKit’s avatar protocol. Each signal of that protocol maps to a track, a command, or a message of the model:
From the agent: byte streams on lk.audio_stream feed the agent_audio input track. The lk.clear_buffer RPC runs the clear_buffer command. Data packets on avatar.user_speaking_state run the user_speaking_state command. Back to the room: the main_video and main_audio output tracks are published as the avatar's video and audio. The playback_started and playback_finished messages go back to the agent as the lk.playback_started and lk.playback_finished RPCs.
The runtime.livekit block in reactor.yaml declares this mapping. The output tracks need no entry, because the runtime publishes them to the room:
reactor.yaml (the livekit block)
set_avatar is not mapped to the room. The portrait arrives in the starting input of the session. The runtime.livekit reference explains each key.

Between the app and the model

The app and the model exchange 2 dataclasses, and the model implements 2 methods:
avatar_contract.py (simplified)
Another avatar model can use the same app: it implements AvatarModel. The example’s second model, LiveAvatar in liveavatar-model/, does exactly that, with the same avatar_app.py and avatar_contract.py.

Loading

The runtime calls load() once, when the instance starts and before any session. AvatarApp.load() reads config.yml and calls create_model(), which AuraAvatar implements:
aura_app.py (simplified)
AuraModel.load() builds AURA’s pipeline from the weights folder, the way AURA builds it from Hugging Face, so the model never reads the network. It then compiles the transformer and renders 6 warmup chunks, so the first call runs at full speed. create_model() also returns a default portrait, which a session uses until set_avatar replaces it.

The render loop

Most models leave the loop to the runtime and write the three step hooks. This app writes its own run() instead. The render runs on a worker thread, so commands and speech keep arriving while a chunk renders:
avatar_app.py (simplified)

Plan a chunk

The agent’s speech arrives on agent_audio faster than it plays, as one byte stream per utterance. A background task collects it into utterances. The next chunk carries 1.0 second of one utterance as soon as that much is in, or the last, shorter part when the utterance ends. With no speech, the next chunk is idle:
avatar_app.py (simplified)
Speech renders at most 2 seconds ahead of what plays (speech_lead_s in config.yml). That is enough to keep the next chunk ready, and an interrupt drops little rendered speech.

Render the chunk

render() calls generate() on the model, on the worker thread. When the model does not hold the portrait, it starts a new clip from it. Then it renders the chunk from its speech:
aura_model.py (simplified)
AURA reads speech as features of Kyutai’s Mimi codec. It normally encodes a whole recording at once, so here each chunk’s features come from the chunk’s speech plus up to 4 seconds before it (audio_context_s in config.yml). The model keeps its key/value cache between chunks, so each chunk continues from the frames before it.

Send the frames with their audio

send_block() sends the chunk’s frames together with the exact speech that drove them. The runtime plays the two in lockstep, so the mouth matches the sound:
avatar_app.py (simplified)
Each frame plays with 1,500 samples of speech: 1/16 of a second at 24 kHz. A playout clock records when each chunk plays, which dates the playback reports.

Interrupts and playback reports

When you talk over the avatar, the agent sends lk.clear_buffer, which runs clear_buffer:
avatar_app.py (simplified)
clear_buffer runs on the event loop, so it takes effect even while a chunk renders. When that chunk is done, send_block() drops it. The agent uses the playback reports to know what you heard. playback_started goes back when the first frame of an utterance plays. playback_finished goes back when the utterance has played to its end, or when clear_buffer cut it, with how many seconds of it played.

When the model fails

An error in generate() during a call stops that call, not the runtime. run() catches it and calls fail():
avatar_app.py (simplified)
The picture freezes on its last frame, and avatar_failed tells the client why. When the session ends, the model is reset as after every session, and the next call starts normally.

The portrait

set_avatar takes the portrait. Only the starting input of the session can send it, so a participant in the room cannot change the face:
avatar_app.py (simplified)
Each portrait gets an id that is unique for the life of the runtime. The app compares it with the portrait the model holds, so the next chunk carries the portrait whenever the model needs it, and starts a new clip from it.

Sessions and reset

  • Session start: @session_started creates the session’s state from the default portrait, and starts the tasks that collect the speech and send the playback reports.
  • Session end: @session_ended stops those tasks, drops the queued speech and media, and has the loop reset the model before the next session.