livekit-plugins-bithuman 1.0.22__py3-none-any.whl → 1.1.0__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.
@@ -8,9 +8,9 @@ import cv2
8
8
  import numpy as np
9
9
  from loguru import logger as _logger
10
10
 
11
- from bithuman import AsyncBithuman
11
+ from bithuman import AsyncBithuman # type: ignore
12
12
  from livekit import rtc
13
- from livekit.agents import NOT_GIVEN, AgentSession, NotGivenOr, utils
13
+ from livekit.agents import NOT_GIVEN, AgentSession, NotGivenOr, get_job_context, utils
14
14
  from livekit.agents.voice.avatar import (
15
15
  AudioSegmentEnd,
16
16
  AvatarOptions,
@@ -39,11 +39,12 @@ class AvatarSession:
39
39
  api_url: NotGivenOr[str] = NOT_GIVEN,
40
40
  api_secret: NotGivenOr[str] = NOT_GIVEN,
41
41
  api_token: NotGivenOr[str] = NOT_GIVEN,
42
+ runtime: NotGivenOr[AsyncBithuman | None] = NOT_GIVEN,
42
43
  ) -> None:
43
- self._api_url = api_url or os.getenv("BITHUMAN_API_URL")
44
- self._api_secret = api_secret or os.getenv("BITHUMAN_API_SECRET")
45
- self._api_token = api_token or os.getenv("BITHUMAN_API_TOKEN")
46
- self._model_path = model_path or os.getenv("BITHUMAN_MODEL_PATH")
44
+ self._api_url = api_url or (os.getenv("BITHUMAN_API_URL") or NOT_GIVEN)
45
+ self._api_secret = api_secret or (os.getenv("BITHUMAN_API_SECRET") or NOT_GIVEN)
46
+ self._api_token = api_token or (os.getenv("BITHUMAN_API_TOKEN") or NOT_GIVEN)
47
+ self._model_path = model_path or (os.getenv("BITHUMAN_MODEL_PATH") or NOT_GIVEN)
47
48
 
48
49
  if self._api_secret is None and self._api_token is None:
49
50
  raise BitHumanException("BITHUMAN_API_SECRET or BITHUMAN_API_TOKEN must be set")
@@ -51,22 +52,39 @@ class AvatarSession:
51
52
  raise BitHumanException("BITHUMAN_MODEL_PATH must be set")
52
53
 
53
54
  self._avatar_runner: AvatarRunner | None = None
55
+ self._runtime = runtime
54
56
 
55
57
  async def start(self, agent_session: AgentSession, room: rtc.Room) -> None:
56
- kwargs = {
57
- "model_path": self._model_path,
58
- }
59
- if self._api_secret:
60
- kwargs["api_secret"] = self._api_secret
61
- if self._api_token:
62
- kwargs["token"] = self._api_token
63
- if self._api_url:
64
- kwargs["api_url"] = self._api_url
65
-
66
- runtime = await AsyncBithuman.create(**kwargs)
67
- await runtime.start()
58
+ if self._runtime:
59
+ runtime = self._runtime
60
+ await runtime._initialize_token() # refresh the token
61
+ else:
62
+ kwargs = {
63
+ "model_path": self._model_path,
64
+ }
65
+ if self._api_secret:
66
+ kwargs["api_secret"] = self._api_secret
67
+ if self._api_token:
68
+ kwargs["token"] = self._api_token
69
+ if self._api_url:
70
+ kwargs["api_url"] = self._api_url
71
+
72
+ runtime = await AsyncBithuman.create(**kwargs)
73
+ self._runtime = runtime
74
+ await runtime.start()
75
+
68
76
  video_generator = BithumanGenerator(runtime)
69
77
 
78
+ try:
79
+ job_ctx = get_job_context()
80
+
81
+ async def _on_shutdown() -> None:
82
+ runtime.cleanup()
83
+
84
+ job_ctx.add_shutdown_callback(_on_shutdown)
85
+ except RuntimeError:
86
+ pass
87
+
70
88
  output_width, output_height = video_generator.video_resolution
71
89
  avatar_options = AvatarOptions(
72
90
  video_width=output_width,
@@ -88,6 +106,12 @@ class AvatarSession:
88
106
 
89
107
  agent_session.output.audio = audio_buffer
90
108
 
109
+ @property
110
+ def runtime(self) -> AsyncBithuman:
111
+ if self._runtime is None:
112
+ raise BitHumanException("Runtime not initialized")
113
+ return self._runtime
114
+
91
115
 
92
116
  class BithumanGenerator(VideoGenerator):
93
117
  def __init__(self, runtime: AsyncBithuman):
@@ -102,11 +126,11 @@ class BithumanGenerator(VideoGenerator):
102
126
 
103
127
  @property
104
128
  def video_fps(self) -> int:
105
- return self._runtime.settings.FPS
129
+ return self._runtime.settings.FPS # type: ignore
106
130
 
107
131
  @property
108
132
  def audio_sample_rate(self) -> int:
109
- return self._runtime.settings.INPUT_SAMPLE_RATE
133
+ return self._runtime.settings.INPUT_SAMPLE_RATE # type: ignore
110
134
 
111
135
  @utils.log_exceptions(logger=logger)
112
136
  async def push_audio(self, frame: rtc.AudioFrame | AudioSegmentEnd) -> None:
File without changes
@@ -12,4 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- __version__ = "1.0.22"
15
+ __version__ = "1.1.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: livekit-plugins-bithuman
3
- Version: 1.0.22
3
+ Version: 1.1.0
4
4
  Summary: Agent Framework plugin for services from BitHuman Avatar Rendering
5
5
  Project-URL: Documentation, https://docs.livekit.io
6
6
  Project-URL: Website, https://livekit.io/
@@ -17,8 +17,8 @@ Classifier: Topic :: Multimedia :: Sound/Audio
17
17
  Classifier: Topic :: Multimedia :: Video
18
18
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
19
  Requires-Python: >=3.9.0
20
- Requires-Dist: bithuman>=0.5.5
21
- Requires-Dist: livekit-agents>=1.0.22
20
+ Requires-Dist: bithuman>=0.5.10
21
+ Requires-Dist: livekit-agents>=1.1.0
22
22
  Description-Content-Type: text/markdown
23
23
 
24
24
  # BitHuman plugin for LiveKit Agents
@@ -0,0 +1,8 @@
1
+ livekit/plugins/bithuman/__init__.py,sha256=yEz6LYNiykKKobr6e20vHipDN6Xzi61oRtnUoMZSDDw,1280
2
+ livekit/plugins/bithuman/avatar.py,sha256=-_KZVRTOaugekQ5S1EDiLb0tdJy-G4wRZoAeK3X3qm0,5952
3
+ livekit/plugins/bithuman/log.py,sha256=1lFUaugLdHDmBqFuNz2Z70iMRyuOtQ9KkL5h3ney0So,71
4
+ livekit/plugins/bithuman/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ livekit/plugins/bithuman/version.py,sha256=lFVJxRoJYH4JZgg7iJQF0_dlrbfVbRYYWQzbHnv_p-w,600
6
+ livekit_plugins_bithuman-1.1.0.dist-info/METADATA,sha256=kvcDh_djeJp8TAamPGBJQQ4BKwkuq_zV0-gOizoAdlg,1178
7
+ livekit_plugins_bithuman-1.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ livekit_plugins_bithuman-1.1.0.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- livekit/plugins/bithuman/__init__.py,sha256=yEz6LYNiykKKobr6e20vHipDN6Xzi61oRtnUoMZSDDw,1280
2
- livekit/plugins/bithuman/avatar.py,sha256=XdvsIhKofmtDTJKe6Je2Yx67fzcbd1ikM2MTYvaztxs,5089
3
- livekit/plugins/bithuman/log.py,sha256=1lFUaugLdHDmBqFuNz2Z70iMRyuOtQ9KkL5h3ney0So,71
4
- livekit/plugins/bithuman/version.py,sha256=fFh0krgNqxKvDz0uOvDLACfvE24LL65uGmzGKWgu_wM,601
5
- livekit_plugins_bithuman-1.0.22.dist-info/METADATA,sha256=psu4A7HZ3aDvV0ZPT3qvpgKT6CFHjntTaCoJ4zJ5jgA,1179
6
- livekit_plugins_bithuman-1.0.22.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- livekit_plugins_bithuman-1.0.22.dist-info/RECORD,,