Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions examples/avatar_agents/ojin/agent_worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""Ojin avatar agent example.

This example demonstrates how to use the Ojin avatar plugin with LiveKit Agents.
The Ojin avatar captures TTS audio, sends it to the Ojin WebSocket API, and
publishes synchronized avatar video/audio tracks to the room.

Environment variables required:
OJIN_API_KEY: Your Ojin API key
OJIN_CONFIG_ID: Your Ojin avatar configuration ID
OJIN_WS_URL: (Optional) Ojin WebSocket URL (default: wss://models.ojin.ai/realtime)
LIVEKIT_URL: LiveKit server URL
LIVEKIT_API_KEY: LiveKit API key
LIVEKIT_API_SECRET: LiveKit API secret
OPENAI_API_KEY: OpenAI API key (for the LLM)
"""

import logging

from dotenv import load_dotenv

from livekit.agents import (
Agent,
AgentServer,
AgentSession,
JobContext,
TurnHandlingOptions,
cli,
)
from livekit.plugins import ojin, openai

logger = logging.getLogger("ojin-avatar-example")
logger.setLevel(logging.INFO)

load_dotenv()

server = AgentServer()


@server.rtc_session()
async def entrypoint(ctx: JobContext):
session = AgentSession(
llm=openai.realtime.RealtimeModel(voice="ash"),
turn_handling=TurnHandlingOptions(
interruption={"resume_false_interruption": False},
),
)

# Create and start the Ojin avatar session
# avatar.start() replaces normal TTS publishing to avoid dual audio
ojin_avatar = ojin.AvatarSession()
await ojin_avatar.start(session, room=ctx.room)

await session.start(
agent=Agent(instructions="You are a helpful assistant with an avatar."),
room=ctx.room,
)
session.generate_reply(instructions="say hello to the user")


if __name__ == "__main__":
cli.run_app(server)
2 changes: 1 addition & 1 deletion livekit-agents/livekit/agents/voice/avatar/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(
video_fps=options.video_fps,
video_queue_size_ms=self._queue_size_ms,
)
self._read_audio_task: asyncio.Task[None] | None = None
self._read_audio_atask: asyncio.Task[None] | None = None
self._forward_video_atask: asyncio.Task[None] | None = None
self._room_connected_fut = asyncio.Future[None]()

Expand Down
1 change: 1 addition & 0 deletions livekit-agents/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ mistralai = ["livekit-plugins-mistralai>=1.5.1"]
neuphonic = ["livekit-plugins-neuphonic>=1.5.1"]
nltk = ["livekit-plugins-nltk>=1.5.1"]
nvidia = ["livekit-plugins-nvidia>=1.5.1"]
ojin = ["livekit-plugins-ojin>=0.1.0"]
openai = ["livekit-plugins-openai>=1.5.1"]
resemble = ["livekit-plugins-resemble>=1.5.1"]
rime = ["livekit-plugins-rime>=1.5.1"]
Expand Down
32 changes: 32 additions & 0 deletions livekit-plugins/livekit-plugins-ojin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# LiveKit Plugins Ojin

Agent Framework plugin for [Ojin](https://ojin.ai) avatars.

## Installation

```bash
pip install livekit-plugins-ojin
```

## Usage

```python
from livekit.agents import AgentSession
from livekit.plugins import ojin

avatar = ojin.AvatarSession(
api_key="your-api-key",
config_id="your-config-id",
)

# In your agent entrypoint function:
await avatar.start(agent_session, room)
```

See the [examples](../../examples/avatar_agents/ojin/) for a complete working implementation.

## Environment Variables

- `OJIN_API_KEY`: Your Ojin API key
- `OJIN_CONFIG_ID`: Your Ojin configuration ID
- `OJIN_WS_URL`: WebSocket URL (optional, defaults to `wss://models.ojin.ai/realtime`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2025 LiveKit, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Ojin avatar plugin for LiveKit Agents"""

from .avatar import AvatarSession
from .errors import OjinException
from .version import __version__

__all__ = [
"AvatarSession",
"OjinException",
"__version__",
]

from livekit.agents import Plugin

from .log import logger


class OjinPlugin(Plugin):
def __init__(self) -> None:
super().__init__(__name__, __version__, __package__, logger)


Plugin.register_plugin(OjinPlugin())
Loading
Loading