Skip to main content

Agent Framework plugin for SpatialReal Avatar

Project description

LiveKit Agents Plugin for SpatialReal Avatar

This plugin provides integration with SpatialReal's avatar service for lip-synced avatar rendering in LiveKit voice agents.

Installation

pip install livekit-plugins-spatialreal

Or install from source:

pip install -e .

Configuration

Set the following environment variables:

# Required
SPATIALREAL_API_KEY=your-api-key
SPATIALREAL_APP_ID=your-app-id
SPATIALREAL_AVATAR_ID=your-avatar-id

# Optional
SPATIALREAL_CONSOLE_ENDPOINT=
SPATIALREAL_INGRESS_ENDPOINT=

# LiveKit credentials
LIVEKIT_URL=
LIVEKIT_API_KEY=
LIVEKIT_API_SECRET=

Usage

from livekit.agents import Agent, AgentSession, JobContext, cli, WorkerOptions
from livekit.plugins import spatialreal


class VoiceAssistant(Agent):
    def __init__(self):
        super().__init__(instructions="You are a helpful voice assistant.")


async def entrypoint(ctx: JobContext):
    await ctx.connect()

    # Configure your pipeline components (VAD, STT, LLM, TTS)
    session = AgentSession(
        vad=vad,
        stt=stt,
        llm=llm,
        tts=tts,
    )

    # Initialize and start the avatar session
    avatar = spatialreal.AvatarSession()
    await avatar.start(session, room=ctx.room)

    # Start the agent session
    await session.start(
        agent=VoiceAssistant(),
        room=ctx.room,
    )


if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))

For production agents, catch SpatialRealException so you can decide whether to fail the job or continue without avatar output:

try:
    await avatar.start(session, room=ctx.room)
except spatialreal.SpatialRealException as err:
    logger.error("Avatar startup failed: %s", err)
    raise

API Reference

AvatarSession

Main class for integrating SpatialReal avatars with LiveKit agents.

Constructor Parameters

Parameter Type Description
api_key str SpatialReal API key (or set SPATIALREAL_API_KEY)
app_id str SpatialReal application ID (or set SPATIALREAL_APP_ID)
avatar_id str Avatar ID to use (or set SPATIALREAL_AVATAR_ID)
console_endpoint_url str Custom console endpoint URL
ingress_endpoint_url str Custom ingress endpoint URL
avatar_participant_identity str LiveKit identity for avatar participant
avatar_participant_name str LiveKit display name for avatar participant
idle_timeout_seconds int LiveKit egress idle timeout in seconds (0 uses server defaults)
sample_rate int | None Optional avatar audio sample rate override

Methods

  • start(agent_session, room, *, livekit_url, livekit_api_key, livekit_api_secret): Start the avatar session and hook into the agent's audio output. Raises SpatialRealException with actionable context if startup fails.
  • aclose(): Clean up avatar session resources.

When starting, the plugin automatically sets lk.publish_on_behalf to the agent participant identity for avatar worker association in LiveKit frontends.

SpatialRealException

Exception raised for SpatialReal-related errors.

How It Works

  1. The plugin intercepts TTS audio output from the agent session
  2. Audio frames are forwarded to SpatialReal's avatar service
  3. SpatialReal generates lip-synced video and audio
  4. The avatar joins the LiveKit room and publishes the synchronized streams

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

livekit_plugins_spatialreal-1.6.6.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

livekit_plugins_spatialreal-1.6.6-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file livekit_plugins_spatialreal-1.6.6.tar.gz.

File metadata

File hashes

Hashes for livekit_plugins_spatialreal-1.6.6.tar.gz
Algorithm Hash digest
SHA256 1a330a9aec784fd44d8fc8a6c0c602b66ab6738842255062cb6bfe7d73720f6d
MD5 350b264c8cbddc39e7eb1a90cf9daa20
BLAKE2b-256 ea32d02f341f70650070421ad1149120a4a654de0fe476d7ef6a4efc58b55a27

See more details on using hashes here.

Provenance

The following attestation bundles were made for livekit_plugins_spatialreal-1.6.6.tar.gz:

Publisher: publish.yml on SpatialReal-ai/livekit-plugins-spatialreal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file livekit_plugins_spatialreal-1.6.6-py3-none-any.whl.

File metadata

File hashes

Hashes for livekit_plugins_spatialreal-1.6.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6e36596255c80975d346ad8a9cd21faef360a5a2676021e59fad6258af23cc77
MD5 f45e36603ebc6dbf2863de29301a3aff
BLAKE2b-256 d997462b4750f4d3fec6173b66a1a85f39aa917cc21eb5b2fea5d51c218cb575

See more details on using hashes here.

Provenance

The following attestation bundles were made for livekit_plugins_spatialreal-1.6.6-py3-none-any.whl:

Publisher: publish.yml on SpatialReal-ai/livekit-plugins-spatialreal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page