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
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
Provides LiveAvatar interactive avatar integration similar to Tavus.
"""

from .api import LiveAvatarException
from .api import LiveAvatarException, VideoQuality
from .avatar import AvatarSession

__all__ = [
"LiveAvatarException",
"AvatarSession",
"VideoQuality",
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import logging
import os
from enum import Enum
from typing import Any

import aiohttp
Expand All @@ -24,6 +25,13 @@ class LiveAvatarException(Exception):
DEFAULT_API_URL = "https://api.liveavatar.com/v1/sessions"


class VideoQuality(str, Enum):
VERY_HIGH = "very_high" # 1080p
HIGH = "high" # 720p
MEDIUM = "medium" # 480p
LOW = "low" # 360p


class LiveAvatarAPI:
def __init__(
self,
Expand Down Expand Up @@ -54,6 +62,7 @@ async def create_streaming_session(
room: rtc.Room,
avatar_id: str,
is_sandbox: bool = False,
video_quality: VideoQuality | None = None,
) -> dict[str, Any]:
"""Create a new streaming session, return a session id"""

Expand All @@ -63,12 +72,14 @@ async def create_streaming_session(
"livekit_client_token": livekit_token,
}

payload = {
payload: dict[str, Any] = {
"mode": "LITE",
"avatar_id": avatar_id,
"is_sandbox": is_sandbox,
"livekit_config": livekit_config,
}
if video_quality is not None:
payload["video_settings"] = {"quality": video_quality.value}

self._headers = {
"accept": "application/json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)
from livekit.agents.voice.room_io import ATTRIBUTE_PUBLISH_ON_BEHALF

from .api import LiveAvatarAPI, LiveAvatarException
from .api import LiveAvatarAPI, LiveAvatarException, VideoQuality
from .log import logger

SAMPLE_RATE = 24000
Expand All @@ -49,6 +49,7 @@ def __init__(
api_url: NotGivenOr[str] = NOT_GIVEN,
api_key: NotGivenOr[str] = NOT_GIVEN,
is_sandbox: NotGivenOr[bool] = NOT_GIVEN,
video_quality: NotGivenOr[VideoQuality] = NOT_GIVEN,
avatar_participant_identity: NotGivenOr[str] = NOT_GIVEN,
avatar_participant_name: NotGivenOr[str] = NOT_GIVEN,
conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS,
Expand All @@ -69,6 +70,9 @@ def __init__(
conn_options=conn_options,
)
self._is_sandbox = is_sandbox if is_given(is_sandbox) else False
self._video_quality: VideoQuality | None = (
video_quality if is_given(video_quality) else None
)

self._avatar_participant_identity = avatar_participant_identity or _AVATAR_AGENT_IDENTITY
self._avatar_participant_name = avatar_participant_name or _AVATAR_AGENT_NAME
Expand Down Expand Up @@ -136,6 +140,7 @@ async def start(
room=self._room,
avatar_id=self._avatar_id,
is_sandbox=self._is_sandbox,
video_quality=self._video_quality,
)
self._session_id = session_config_data["data"]["session_id"]
self._session_token = session_config_data["data"]["session_token"]
Expand Down