Metadata-Version: 2.4
Name: bevyra-avatar
Version: 1.0.10
Summary: API-authorized local BeVyra avatar renderer
License-Expression: LicenseRef-Proprietary
Project-URL: Documentation, https://bevyra.ai/docs
Project-URL: Homepage, https://bevyra.ai/docs
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: aiohttp<4,>=3.10
Requires-Dist: httpx<1,>=0.27
Requires-Dist: numpy<3,>=1.26
Requires-Dist: onnxruntime<2,>=1.22
Requires-Dist: opencv-python-headless<5,>=4.10
Requires-Dist: imageio-ffmpeg<1,>=0.8
Requires-Dist: Pillow<12,>=10

# bevyra-avatar

Run a licensed BeVyra avatar locally from Python. Bring your own ASR, LLM and TTS. The binary wheel supports CPython 3.12 on Linux x86_64 and contains a compiled CPU mesh renderer. Install it from PyPI; no repository clone is required. BeVyra's API authorizes the device and supplies signed avatar downloads. Verified cached bundles are reused without another download grant. Speech follows deterministic contiguous source segments; recorded silence begins after one continuous second of quiet audio, with four-frame transitions.

```bash
python -m pip install --only-binary=:all: bevyra-avatar
export BEVYRA_API_KEY=your_project_key
bevyra-avatar activate --name my-app
bevyra-avatar list
bevyra-avatar assign 1 noora # only on plans with avatar slots
bevyra-avatar download noora
bevyra-avatar serve
```

`assign` is needed on plans with avatar slots. `download` verifies the model and stores it under the user-writable `~/.local/share/bevyra-avatar` directory by default. Set `BEVYRA_AVATAR_HOME` to another writable path. Existing revisions remain installed when the avatar catalog changes. Each API key may activate three installations. A verified local bundle is reused without spending another download grant, while each session still checks authorization with the API.

```python
import asyncio, os
from bevyra_avatar import AvatarServer, ControlPlane

async def main():
    control = ControlPlane()
    await control.activate(os.environ['BEVYRA_API_KEY'])
    # On plans with avatar slots: await control.assign(1, 'noora')
    await control.download('noora')
    async with AvatarServer() as server:
        print(server.url, server.token)
        await asyncio.Event().wait()

asyncio.run(main())
```

The service binds only to loopback. Authenticate `/v1/stream` with `Authorization: Bearer <token>`. Send `session.setup` with an avatar ID and optional `background`, `width`, and `height`. `background` accepts `#RRGGBB` or a base64 data URL for JPEG, PNG, GIF, or WebP. GIF and animated WebP loop continuously across speech and idle frames. JPEG, PNG, and single-frame WebP are still images. Without a background, speech and idle JPEGs are composited over off-white `#F5F3EE`. Images fill the output by center cropping; the avatar keeps its aspect ratio. Both width and height must be 160–1920 pixels and output area may not exceed 2.07 megapixels. Image input is limited to 8 MiB and 64–4096 pixels per side. Animations are limited to 300 frames and 30 seconds. Then send `clause.start` with a clause ID and sample count, binary signed PCM16 mono at 16 kHz, and `clause.end`. It returns `session.ready`, `clause.audio` plus PCM, `clause.frame` plus JPEG for each 40 ms frame, and `clause.done`. Frames carry `timestampMs` relative to the clause audio. During idle, send `session.idle` with `count` from 1 to 9; the server returns `idle.frame` plus JPEG at 40 ms intervals and `idle.done`. `session.interrupt` cancels the current clause. Include natural pauses in each speech unit for planner context.

To send a local background file from Python:

```python
import base64
import mimetypes
from pathlib import Path

def image_background(path: str) -> str:
    file = Path(path)
    mime = mimetypes.guess_type(file)[0]
    if mime not in {"image/jpeg", "image/png", "image/gif", "image/webp"}:
        raise ValueError("Use JPEG, PNG, GIF or WebP")
    return f"data:{mime};base64,{base64.b64encode(file.read_bytes()).decode()}"

# Use one of these values in session.setup:
# Omit background for off-white; use "#FFFFFF" for white.
background = image_background("background.png")   # Still image
background = image_background("background.gif")   # Animated and looping
background = image_background("background.webp")  # Still or animated
await ws.send_json({"type": "session.setup", "avatar": "noora",
                    "background": background, "width": 720, "height": 1280})
```

After `session.ready`, send `clause.start`, the PCM bytes, and `clause.end`. Read each `clause.audio` or `clause.frame` JSON message followed by its binary payload; play the audio once and display each JPEG at its `timestampMs`. A complete copyable stream example is on the [developer page](https://bevyra.ai/docs).

Only prebuilt binary wheels are distributed. Activation, authorization refresh, and new avatar downloads require API access; rendering uses local CPU and installed files.

When an inference update requires a newer SDK, the service rejects old installations with HTTP 426 `sdk_update_required` before starting a session. Update with `python -m pip install --upgrade bevyra-avatar`, then restart the local renderer. The verified avatar cache stays in place.
