Syncing Pipecat Voice Agent States with a Lightweight Rive Avatar
By the Charmotion team · Updated · How we write guides

Forward Pipecat's speaking, transcription, interruption and error events from the browser client to a Rive state machine input, and map each event to a numbered mood. The avatar then reacts in real time from one small .riv file. The rest is a single lookup table.
Key takeaways
- Pipecat frames reach the browser as client events, and the browser turns those events into one mood number.
- Keep one lookup table that links events, mood names and numbers, outside the transport code.
- Debounce thinking and attention, and return from sad to listening, so the face does not flicker.
- Use one Rive instance with one state machine input, and check the export plan before launch.
Already have a character or logo? See examples in real app screens: splash, onboarding, loading and empty-state screens, with the animation that plays in each.
Which Pipecat events should drive an avatar?
This guide covers how to sync Pipecat voice agent events with a lightweight Rive character avatar, from the server pipeline to a state machine running in the browser. Pipecat is an open source Python framework for voice and multimodal AI agents. On the server it chains transport, speech recognition, LLM and speech synthesis steps into a frame-processing pipeline, and browser, mobile and C++ clients connect to that pipeline over WebRTC or WebSocket.
Frames are the signals that move through the pipeline. Pipecat's pipeline docs list system frames such as InputAudioRawFrame, UserStartedSpeakingFrame, InterruptionFrame and ErrorFrame, and data frames such as TranscriptionFrame and TTSAudioRawFrame. An avatar does not need the audio itself. It needs four answers: is the user speaking, is the agent working, is the agent talking, and did something go wrong.
- User starts speaking (UserStartedSpeakingFrame): the avatar should listen.
- Transcript arrives (TranscriptionFrame): the user's turn is over and the agent is working, so the avatar should think.
- Bot audio plays (TTSAudioRawFrame on the server): the avatar talks.
- Interruption (InterruptionFrame): the user cut the agent off, so the avatar shows attention.
- Error (ErrorFrame): the avatar shows sad.
Those five cases cover most of a voice session. The browser receives them as client events rather than raw frames, as the next sections explain. For the same idea on a different voice backend, see voice agent avatar event mapping for OpenAI Realtime.
How do you map Pipecat events to avatar moods?
Use one lookup table, and keep it in its own module so a designer can change a mood without touching transport code. The mood numbers below match the ones Charmotion uses in its character files: idle 0, happy 1, wave 2, thinking 3, sad 4, loading 5, listening 6, talking 7, sleeping 8 and attention 9. Any Rive file with a numeric input works with the same table, as long as the numbers agree.
| Client event | What it means | Mood | Number |
|---|---|---|---|
| Session connecting | Transport is opening | loading | 5 |
| Bot ready | Agent can take a turn | idle | 0 |
| User started speaking | Microphone picked up speech | listening | 6 |
| Transcript received | User turn finished, agent working | thinking | 3 |
| Bot speaking started | Agent audio is playing | talking | 7 |
| Bot speaking stopped | Turn finished | idle | 0 |
| Interruption | User cut in | attention | 9 |
| Error | Something failed | sad | 4 |
| Task success (your app event) | Tool or task completed | happy | 1 |
| Long silence (your timer) | No turns for a while | sleeping | 8 |
The table is deliberately short. Pipecat sends more events than an avatar needs, and most of them should not change the face. Only turn boundaries, interruptions and errors should. For mouth shapes that follow audio levels rather than turn state, compare the approaches in lip-sync vs amplitude for a talking avatar.
How do you receive those events in the browser?
On the server, the RTVI observer converts pipeline frames into outgoing client messages, including user and bot speaking events and transcriptions. The client SDKs implement the RTVI protocol, so the browser side stays the same whether the server is Pipecat or another RTVI-compatible server. In JavaScript the client is PipecatClient from the @pipecat-ai/client-js package, and it takes a transport instance such as DailyTransport.
The SDK also manages WebRTC or WebSocket connections, microphone and camera devices, and connect, disconnect and reconnect sessions. Your avatar code only has to listen for events and forward a mood. The event names come from the SDK, so check the client reference for your version before wiring each one. The labels in the code below are your own, and each one should be matched to the SDK event that fires it.
export const MOOD = { idle: 0, happy: 1, wave: 2, thinking: 3, sad: 4, loading: 5, listening: 6, talking: 7, sleeping: 8, attention: 9 };
export function moodFor(event) {
switch (event) {
case 'connecting': return MOOD.loading;
case 'ready': return MOOD.idle;
case 'user-start': return MOOD.listening;
case 'transcript': return MOOD.thinking;
case 'bot-start': return MOOD.talking;
case 'bot-stop': return MOOD.idle;
case 'interrupt': return MOOD.attention;
case 'error': return MOOD.sad;
default: return null;
}
}
Route each SDK event through moodFor, then store the result in React state. Keep that state in the component that owns the avatar, so one Rive instance handles every turn. The same kind of state-change wiring appears in ElevenLabs agent avatar with onModeChange, which uses a different voice stack.
How do you drive a Rive state machine input from the client?
Rive's React runtime, @rive-app/react-canvas, exposes a useRive hook that returns a Rive instance and a component to render, plus a useStateMachineInput hook for reading and setting a state machine input. The help page marks the input hook as deprecated in favour of the newer data binding hooks. For a single number input it still works, so this example uses it. When the avatar needs several typed values, move to data binding, as explained in data binding vs state machine inputs.
import { useRive, useStateMachineInput } from '@rive-app/react-canvas';
import { useEffect } from 'react';
export function Avatar({ mood }) {
const { rive, RiveComponent } = useRive({
src: '/avatar.riv',
stateMachines: 'CharacterStateMachine',
autoplay: true,
});
const moodInput = useStateMachineInput(rive, 'CharacterStateMachine', 'mood');
useEffect(() => {
if (moodInput && typeof mood === 'number') {
moodInput.value = mood;
}
}, [mood, moodInput]);
return <RiveComponent />;
}
The state machine name and input name must match the .riv file exactly. In a Charmotion character file, CharacterStateMachine has a number input called mood, and CharacterViewModelMachine has a number property with the same name, so either route can drive the face. Charmotion's character output includes an accents boolean that hides the small Z z z, thinking dots, exclamation mark and sparkles, which suits an avatar that sits beside a live transcript. Characters have no one-shot triggers, so a success is happy and an error is sad, as the table shows. The character files are described on the AI chatbot avatar animation page.
How do you handle interruptions, errors and quick changes?
Voice turns change fast. A short 'yes' can trigger listening, thinking and talking within a few seconds, and without guards the face flickers between moods. Four rules prevent that.
- Write only on change. Skip the input write when the mood equals the last value you sent.
- Hold thinking briefly. Show thinking after the transcript, and cancel it as soon as talking starts. A delay of around 300 milliseconds before thinking stops flicker on fast replies. This is a tuning choice you should test, not a platform setting.
- Keep attention short. After an interruption, show attention for about a second, then move to listening if the user is still speaking.
- Return from sad to listening. An error shows sad until the next user-start event, which returns the avatar to listening rather than to idle.
Reconnects need a rule of their own. When the client disconnects, set the avatar to loading, and return to idle only after the bot-ready event arrives on the new session. Pipecat's client handles the reconnect itself, so the avatar only has to show the state it receives. For streaming states in a chat interface, the same debouncing logic appears in animating a chat avatar from streaming events.
How do you keep the avatar lightweight in production?
The avatar is one .riv file and one canvas. Mount the Rive component once per avatar and change its input on each event, instead of creating a new instance for every turn. Stop rendering when the avatar is off screen or the tab is hidden, and load the Rive runtime only on pages that show the avatar.
Rive's WASM runtime loads from the default unpkg CDN unless you host it yourself. If your site has a strict content policy, or you want the runtime on the same origin, host rive.wasm on your own server and point the runtime at it. Test that setup in your own build before you rely on it.
Plan the export before the design is final. On Rive's Free plan, exported files play a Rive splash screen, and paid plans export without it, so a live voice avatar usually needs a paid export. The guide on whether Rive is free covers the plan differences, and Rive's pricing page lists current plans.
Hosted sessions have a cost too. Pipecat's docs do not document Pipecat Cloud pricing or usage limits (as of December 2026), so check Pipecat's own pages before you budget for hosted sessions. Self-hosting the pipeline keeps the server side on infrastructure you control.
Test every row of the mood table in a real session before launch. Include a deliberate interruption and a forced error, and watch the avatar's frame rate on the lowest-powered device you support.
How to sync Pipecat voice agent events with a Rive avatar
- Run the pipeline with the RTVI observer. Run your Pipecat pipeline with the RTVI observer enabled so the server sends user and bot speaking events and transcriptions to the browser.
- Connect the browser client. Create a PipecatClient from @pipecat-ai/client-js with your transport instance, such as DailyTransport, and let the SDK manage the connection.
- Write the mood table. Put the mood names and numbers in one module, using idle 0, happy 1, wave 2, thinking 3, sad 4, loading 5, listening 6, talking 7, sleeping 8 and attention 9.
- Map SDK events to moods. Match each client event to a mood with a single function such as moodFor, and check each event name against the client SDK reference for your version.
- Bind the mood input in the Rive file. Load the .riv file with its state machine and set the mood number input from React state, using a useStateMachineInput hook or data binding.
- Add debounce rules and test. Write only on change, hold thinking briefly, keep attention short, return from sad to listening, and test every mood with a real session including an interruption and an error.
Frequently asked questions
Does Pipecat need a paid hosting plan to run this?
No. Pipecat is an open source Python framework, so you can run the pipeline on your own server. Pipecat Cloud is a hosted option, but Pipecat's docs do not document its pricing or usage limits (as of December 2026). Check the Pipecat site before you budget for it. The browser avatar code works with either setup.
Can the same avatar code work with a server that is not Pipecat?
Yes, if that server speaks RTVI. The client SDKs implement the RTVI protocol, so they can work with RTVI-compatible servers. The mood table stays the same as long as the server sends equivalent speaking, transcript, interruption and error events.
Does the free Rive plan work for a live voice avatar?
Free-plan exports play a Rive splash screen, which most live voice interfaces will not want. Paid plans export without the splash screen. Check the Rive plan details on this site and on Rive's pricing page before you ship the avatar.
Why not drive the avatar from audio levels instead?
Audio levels only show that sound is present. Pipecat's events also tell you whether the user is speaking, the agent is working, or a turn was interrupted, so the states are more accurate. You can combine both approaches, with turn events for moods and audio for mouth shapes.
Sources
- Pipecat introduction, Pipecat
- Pipeline, Pipecat
- Client SDKs introduction, Pipecat
- Rive Editor, Rive
- Rive React runtime, Rive
- Rive pricing, Rive