> ## Documentation Index
> Fetch the complete documentation index at: https://docs.simli.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pipecat

> Give a Pipecat voice agent a lip-synced Simli avatar

[Pipecat](https://docs.pipecat.ai) is an open-source Python framework for voice and multimodal agents. Simli's video service drops into a Pipecat pipeline: it takes the bot's voice and returns the avatar's lip-synced video and voice, in sync.

## What you need

* A Simli API key, from your [Simli dashboard](https://app.simli.com)
* An [OpenAI API key](https://platform.openai.com/api-keys). The starter uses OpenAI's Realtime API, speech to speech, so there's no separate speech-to-text or text-to-speech provider.
* Python 3.11 or later (the starter uses [uv](https://docs.astral.sh/uv/)), and [Node.js](https://nodejs.org) 20.9 or later for the starter's web page

Everything runs on your machine: Pipecat connects the browser to the bot over peer-to-peer WebRTC, so there are no other accounts or media servers to set up.

## Run the starter

> [card] [create-simli-app-pipecat](https://github.com/simliai/create-simli-app-pipecat)
>
> A Pipecat voice agent on OpenAI's Realtime API, with a Simli Trinity-2 avatar and a small web page to talk to it. Its lockfile pins the versions it was tested with.

```bash theme={null}
git clone https://github.com/simliai/create-simli-app-pipecat
cd create-simli-app-pipecat
uv sync
cp .env.example .env   # then paste in your keys
uv run bot.py -t webrtc
```

In a second terminal, start the web page:

```bash theme={null}
cd frontend && npm install && npm run dev
```

Open [http://localhost:3000](http://localhost:3000), press **Start** and allow the microphone. The page holds no keys: it posts its WebRTC offer to its own `/api/offer` route, which forwards it to the bot. If the bot isn't on [http://localhost:7860](http://localhost:7860), set `BOT_URL` in `frontend/.env.local`. Pipecat's prebuilt client at [http://localhost:7860](http://localhost:7860) works too.

## Build it yourself

### 1. Install the packages

```bash theme={null}
pip install "pipecat-ai[openai,runner,simli,webrtc]>=1.16" python-dotenv
```

### 2. Set your keys

Put them in a `.env` file next to your bot:

```bash .env theme={null}
SIMLI_API_KEY=...
OPENAI_API_KEY=...
```

### 3. Add the avatar to your pipeline

This is the core of the starter's bot: the transport, the Simli service and the pipeline. The [starter's `bot.py`](https://github.com/simliai/create-simli-app-pipecat/blob/main/bot.py) has the complete file, with the imports, the OpenAI Realtime service and the runner.

```python bot.py theme={null}
transport = SmallWebRTCTransport(
    webrtc_connection=runner_args.webrtc_connection,
    params=TransportParams(
        audio_in_enabled=True,
        audio_out_enabled=True,
        video_out_enabled=True,
        video_out_is_live=True,
        video_out_width=768,  # Simli's default video size
        video_out_height=768,
        video_out_framerate=25,  # Simli streams at 25 fps
    ),
)

# Simli gets the bot's voice and sends back the avatar's video and voice, in sync.
simli = SimliVideoService(
    api_key=os.environ["SIMLI_API_KEY"],
    face_id=os.getenv("SIMLI_FACE_ID") or "14c60d62-6ebf-424d-b626-1f4f91c33b04",
    max_session_length=600,  # seconds, so a forgotten tab doesn't use up your minutes
    max_idle_time=120,
)

pipeline = Pipeline(
    [
        transport.input(),  # the user's microphone
        user_aggregator,
        llm,  # OpenAIRealtimeLLMService: hears the user and answers in voice
        simli,
        transport.output(),  # the avatar's video and voice
        assistant_aggregator,
    ]
)
```

Simli goes right after the service that produces the bot's voice, and before the transport's output.

### Trinity-2 options

This gives a Trinity-2 face Simli's default 768x768 video. From Pipecat 1.16, `SimliVideoService` takes [Trinity-2's framing](https://docs.simli.com/api-reference/trinity-2.md#framing-the-video) itself. Set the transport's video to the same size:

```python theme={null}
WIDTH, HEIGHT = 1366, 768  # 1:1, 16:9 or 9:16, each side at least 512

simli = SimliVideoService(
    api_key=os.environ["SIMLI_API_KEY"],
    face_id=os.getenv("SIMLI_FACE_ID") or "14c60d62-6ebf-424d-b626-1f4f91c33b04",
    max_session_length=600,
    max_idle_time=120,
    framing=SimliVideoService.Framing(
        streaming_width=WIDTH,
        streaming_height=HEIGHT,
        avatar_position_x=0.5,  # 0 (left) to 1 (right)
        avatar_position_y=1.0,  # 0 (top) to 1 (bottom)
        # camera=SimliVideoService.Camera(zoom=1.2),
        # background_id="<upload id>",
    ),
)
# ...and in TransportParams: video_out_width=WIDTH, video_out_height=HEIGHT
```

Pipecat 1.16 also sends the avatar's video from the start of the session, not only once the bot first speaks, and passes GPT-Live's voice (`OpenAILiveLLMService`) to Simli. On older Pipecat releases, see [Trinity-2 in LiveKit Agents and Pipecat](https://docs.simli.com/api-reference/trinity-2/integration-workarounds.md).

### Video quality with SmallWebRTCTransport

The bot re-encodes the avatar's video before sending it to the browser. With `SmallWebRTCTransport`, that's done by aiortc, which starts at 0.5–1 Mbit/s: too little for a large Trinity-2 video, so the mouth looks smeared and the lip sync looks off. Pipecat has no setting for it, so raise aiortc's limits near the top of `bot.py`:

```python theme={null}
import aiortc.codecs.h264
import aiortc.codecs.vpx

VIDEO_BITRATE = 2_500_000  # bits per second; enough for 1366x768
for codec in (aiortc.codecs.vpx, aiortc.codecs.h264):
    codec.DEFAULT_BITRATE = VIDEO_BITRATE
    codec.MIN_BITRATE = VIDEO_BITRATE // 2
    codec.MAX_BITRATE = VIDEO_BITRATE * 2
```

Lower it for a smaller video or slow networks. Daily and other hosted transports encode the video themselves and don't need this.

### 4. Run it

```bash theme={null}
python bot.py -t webrtc
```

Then open [http://localhost:7860](http://localhost:7860), where Pipecat's runner serves a ready-made browser client, press **Connect** and allow the microphone.

## Before you go to production

The runner is for development.

* **Limit which sites can reach it.** By default Pipecat's runner accepts requests from any website, so a page open in your browser could start a conversation on your accounts. Set `PIPECAT_ALLOWED_ORIGINS=http://localhost:3000,http://localhost:7860` in `.env`; the starter's `.env.example` does. `-t webrtc` turns on only the WebRTC transport.
* **Cap the whole conversation.** Simli's `max_session_length` ends the avatar, but not the pipeline, so the LLM keeps running. The starter cancels the pipeline after the same session length; do the same in your bot.
* **Put sign-in in front of anything that starts a bot.** Anyone who can reach port 7860, or a page that forwards offers to it, can start a conversation that uses your Simli minutes and OpenAI credit. The starter's `/api/offer` route returns `403` in production until you add your own auth.

To deploy, see [Pipecat's deployment guide](https://docs.pipecat.ai/pipecat/deployment/overview).

## Learn more

* The starter's [README](https://github.com/simliai/create-simli-app-pipecat#readme): changing the face, voice and prompt, and how it works
* [Pipecat's guide to Simli](https://docs.pipecat.ai/api-reference/server/services/video/simli)
* [Pipecat docs](https://docs.pipecat.ai): tools, other models and more


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.