livekit-plugins-simli 1.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of livekit-plugins-simli might be problematic. Click here for more details.
- livekit/plugins/simli/__init__.py +40 -0
- livekit/plugins/simli/avatar.py +141 -0
- livekit/plugins/simli/log.py +3 -0
- livekit/plugins/simli/py.typed +0 -0
- livekit/plugins/simli/version.py +15 -0
- livekit_plugins_simli-1.2.2.dist-info/METADATA +29 -0
- livekit_plugins_simli-1.2.2.dist-info/RECORD +8 -0
- livekit_plugins_simli-1.2.2.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Copyright 2023 LiveKit, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Simli virtual avatar plugin for LiveKit Agents
|
|
16
|
+
|
|
17
|
+
See https://docs.livekit.io/agents/integrations/avatar/simli/ for more information.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from .avatar import AvatarSession, SimliConfig
|
|
21
|
+
from .version import __version__
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"Exception",
|
|
25
|
+
"AvatarSession",
|
|
26
|
+
"__version__",
|
|
27
|
+
"SimliConfig",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
from livekit.agents import Plugin
|
|
31
|
+
|
|
32
|
+
from .log import logger
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class SimliPlugin(Plugin):
|
|
36
|
+
def __init__(self) -> None:
|
|
37
|
+
super().__init__(__name__, __version__, __package__, logger)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
Plugin.register_plugin(SimliPlugin())
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import aiohttp
|
|
8
|
+
|
|
9
|
+
from livekit import api, rtc
|
|
10
|
+
from livekit.agents import (
|
|
11
|
+
NOT_GIVEN,
|
|
12
|
+
AgentSession,
|
|
13
|
+
NotGivenOr,
|
|
14
|
+
get_job_context,
|
|
15
|
+
utils,
|
|
16
|
+
)
|
|
17
|
+
from livekit.agents.voice.avatar import DataStreamAudioOutput
|
|
18
|
+
from livekit.agents.voice.room_io import ATTRIBUTE_PUBLISH_ON_BEHALF
|
|
19
|
+
|
|
20
|
+
from .log import logger
|
|
21
|
+
|
|
22
|
+
SAMPLE_RATE = 16000
|
|
23
|
+
_AVATAR_AGENT_IDENTITY = "simli-avatar-agent"
|
|
24
|
+
_AVATAR_AGENT_NAME = "simli-avatar-agent"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass
|
|
28
|
+
class SimliConfig:
|
|
29
|
+
"""
|
|
30
|
+
Args:
|
|
31
|
+
api_key (str): Simli API Key
|
|
32
|
+
face_id (str): Simli Face ID
|
|
33
|
+
emotion_id (str):
|
|
34
|
+
Emotion ID for Trinity Faces, defaults to happy_0.
|
|
35
|
+
See https://docs.simli.com/emotions
|
|
36
|
+
max_session_length (int):
|
|
37
|
+
Absolute maximum session duration, avatar will disconnect after this time
|
|
38
|
+
even if it's speaking.
|
|
39
|
+
max_idle_time (int):
|
|
40
|
+
Maximum duration the avatar is not speaking for before the avatar disconnects.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
api_key: str
|
|
44
|
+
face_id: str
|
|
45
|
+
emotion_id: str = "92f24a0c-f046-45df-8df0-af7449c04571"
|
|
46
|
+
max_session_length: int = 600
|
|
47
|
+
max_idle_time: int = 30
|
|
48
|
+
|
|
49
|
+
def create_json(self) -> dict[str, Any]:
|
|
50
|
+
result: dict[str, Any] = {}
|
|
51
|
+
result["apiKey"] = self.api_key
|
|
52
|
+
result["faceId"] = f"{self.face_id}/{self.emotion_id}"
|
|
53
|
+
result["syncAudio"] = True
|
|
54
|
+
result["handleSilence"] = True
|
|
55
|
+
result["maxSessionLength"] = self.max_session_length
|
|
56
|
+
result["maxIdleTime"] = self.max_idle_time
|
|
57
|
+
return result
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class AvatarSession:
|
|
61
|
+
"""A Simli avatar session"""
|
|
62
|
+
|
|
63
|
+
def __init__(
|
|
64
|
+
self,
|
|
65
|
+
*,
|
|
66
|
+
simli_config: SimliConfig,
|
|
67
|
+
api_url: NotGivenOr[str] = NOT_GIVEN,
|
|
68
|
+
avatar_participant_identity: NotGivenOr[str] = NOT_GIVEN,
|
|
69
|
+
avatar_participant_name: NotGivenOr[str] = NOT_GIVEN,
|
|
70
|
+
) -> None:
|
|
71
|
+
self._http_session: aiohttp.ClientSession | None = None
|
|
72
|
+
self.conversation_id: str | None = None
|
|
73
|
+
self._simli_config = simli_config
|
|
74
|
+
self.api_url = api_url or "https://api.simli.ai"
|
|
75
|
+
self._avatar_participant_identity = avatar_participant_identity or _AVATAR_AGENT_IDENTITY
|
|
76
|
+
self._avatar_participant_name = avatar_participant_name or _AVATAR_AGENT_NAME
|
|
77
|
+
self._ensure_http_session()
|
|
78
|
+
|
|
79
|
+
def _ensure_http_session(self) -> aiohttp.ClientSession:
|
|
80
|
+
if self._http_session is None:
|
|
81
|
+
self._http_session = utils.http_context.http_session()
|
|
82
|
+
|
|
83
|
+
return self._http_session
|
|
84
|
+
|
|
85
|
+
async def start(
|
|
86
|
+
self,
|
|
87
|
+
agent_session: AgentSession,
|
|
88
|
+
room: rtc.Room,
|
|
89
|
+
*,
|
|
90
|
+
livekit_url: NotGivenOr[str] = NOT_GIVEN,
|
|
91
|
+
livekit_api_key: NotGivenOr[str] = NOT_GIVEN,
|
|
92
|
+
livekit_api_secret: NotGivenOr[str] = NOT_GIVEN,
|
|
93
|
+
) -> None:
|
|
94
|
+
livekit_url = livekit_url or (os.getenv("LIVEKIT_URL") or NOT_GIVEN)
|
|
95
|
+
livekit_api_key = livekit_api_key or (os.getenv("LIVEKIT_API_KEY") or NOT_GIVEN)
|
|
96
|
+
livekit_api_secret = livekit_api_secret or (os.getenv("LIVEKIT_API_SECRET") or NOT_GIVEN)
|
|
97
|
+
if not livekit_url or not livekit_api_key or not livekit_api_secret:
|
|
98
|
+
raise Exception(
|
|
99
|
+
"livekit_url, livekit_api_key, and livekit_api_secret must be set "
|
|
100
|
+
"by arguments or environment variables"
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
job_ctx = get_job_context()
|
|
105
|
+
local_participant_identity = job_ctx.token_claims().identity
|
|
106
|
+
except RuntimeError as e:
|
|
107
|
+
if not room.isconnected():
|
|
108
|
+
raise Exception("failed to get local participant identity") from e
|
|
109
|
+
local_participant_identity = room.local_participant.identity
|
|
110
|
+
|
|
111
|
+
livekit_token = (
|
|
112
|
+
api.AccessToken(api_key=livekit_api_key, api_secret=livekit_api_secret)
|
|
113
|
+
.with_kind("agent")
|
|
114
|
+
.with_identity(self._avatar_participant_identity)
|
|
115
|
+
.with_name(self._avatar_participant_name)
|
|
116
|
+
.with_grants(api.VideoGrants(room_join=True, room=room.name))
|
|
117
|
+
# allow the avatar agent to publish audio and video on behalf of your local agent
|
|
118
|
+
.with_attributes({ATTRIBUTE_PUBLISH_ON_BEHALF: local_participant_identity})
|
|
119
|
+
.to_jwt()
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
logger.debug("starting avatar session")
|
|
123
|
+
simli_session_token = await self._ensure_http_session().post(
|
|
124
|
+
f"{self.api_url}/startAudioToVideoSession", json=self._simli_config.create_json()
|
|
125
|
+
)
|
|
126
|
+
simli_session_token.raise_for_status()
|
|
127
|
+
(
|
|
128
|
+
await self._ensure_http_session().post(
|
|
129
|
+
f"{self.api_url}/StartLivekitAgentsSession",
|
|
130
|
+
json={
|
|
131
|
+
"session_token": (await simli_session_token.json())["session_token"],
|
|
132
|
+
"livekit_token": livekit_token,
|
|
133
|
+
"livekit_url": livekit_url,
|
|
134
|
+
},
|
|
135
|
+
)
|
|
136
|
+
).raise_for_status()
|
|
137
|
+
agent_session.output.audio = DataStreamAudioOutput(
|
|
138
|
+
room=room,
|
|
139
|
+
destination_identity=self._avatar_participant_identity,
|
|
140
|
+
sample_rate=SAMPLE_RATE,
|
|
141
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright 2025 LiveKit, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
__version__ = "1.2.2"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: livekit-plugins-simli
|
|
3
|
+
Version: 1.2.2
|
|
4
|
+
Summary: Agent Framework plugin for Simli
|
|
5
|
+
Project-URL: Documentation, https://docs.livekit.io
|
|
6
|
+
Project-URL: Website, https://livekit.io/
|
|
7
|
+
Project-URL: Source, https://github.com/livekit/agents
|
|
8
|
+
Author-email: LiveKit <support@livekit.io>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
Keywords: audio,livekit,realtime,video,webrtc
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
|
18
|
+
Classifier: Topic :: Multimedia :: Video
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.9.0
|
|
21
|
+
Requires-Dist: livekit-agents>=1.2.2
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# Simli Avatar plugin for LiveKit Agents
|
|
25
|
+
|
|
26
|
+
Support for the [Simi](https://simli.com/) virtual avatar.
|
|
27
|
+
|
|
28
|
+
See [https://docs.livekit.io/agents/integrations/avatar/simli/](https://docs.livekit.io/agents/integrations/avatar/simli/) for more information.
|
|
29
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
livekit/plugins/simli/__init__.py,sha256=DE12pJXtLAcpoHbfdc57pLtyYk5_1lv5rLKkiXFoi5Y,1119
|
|
2
|
+
livekit/plugins/simli/avatar.py,sha256=AFFNPo-sNKiIO3XmWAt1B6cpnSIRbaUPaDXrRB3NA8g,5156
|
|
3
|
+
livekit/plugins/simli/log.py,sha256=CboZk97X4_ET5i1F1i1ANlWYdAGxPSV3huAbdPR00_c,68
|
|
4
|
+
livekit/plugins/simli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
livekit/plugins/simli/version.py,sha256=HEPfsPSBZ3rIkyBj712Ik9tN1Z2rZUKSzUk3uWa0unA,600
|
|
6
|
+
livekit_plugins_simli-1.2.2.dist-info/METADATA,sha256=nzQf-0JnzjScfZrwmCh057lwJAXCibCINXV9-Zpp4VI,1198
|
|
7
|
+
livekit_plugins_simli-1.2.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
+
livekit_plugins_simli-1.2.2.dist-info/RECORD,,
|