livekit-plugins-bithuman 1.0.23__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,
@@ -41,10 +41,10 @@ class AvatarSession:
41
41
  api_token: NotGivenOr[str] = NOT_GIVEN,
42
42
  runtime: NotGivenOr[AsyncBithuman | None] = NOT_GIVEN,
43
43
  ) -> None:
44
- self._api_url = api_url or os.getenv("BITHUMAN_API_URL")
45
- self._api_secret = api_secret or os.getenv("BITHUMAN_API_SECRET")
46
- self._api_token = api_token or os.getenv("BITHUMAN_API_TOKEN")
47
- 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)
48
48
 
49
49
  if self._api_secret is None and self._api_token is None:
50
50
  raise BitHumanException("BITHUMAN_API_SECRET or BITHUMAN_API_TOKEN must be set")
@@ -57,6 +57,7 @@ class AvatarSession:
57
57
  async def start(self, agent_session: AgentSession, room: rtc.Room) -> None:
58
58
  if self._runtime:
59
59
  runtime = self._runtime
60
+ await runtime._initialize_token() # refresh the token
60
61
  else:
61
62
  kwargs = {
62
63
  "model_path": self._model_path,
@@ -69,10 +70,21 @@ class AvatarSession:
69
70
  kwargs["api_url"] = self._api_url
70
71
 
71
72
  runtime = await AsyncBithuman.create(**kwargs)
73
+ self._runtime = runtime
72
74
  await runtime.start()
73
75
 
74
76
  video_generator = BithumanGenerator(runtime)
75
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
+
76
88
  output_width, output_height = video_generator.video_resolution
77
89
  avatar_options = AvatarOptions(
78
90
  video_width=output_width,
@@ -94,6 +106,12 @@ class AvatarSession:
94
106
 
95
107
  agent_session.output.audio = audio_buffer
96
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
+
97
115
 
98
116
  class BithumanGenerator(VideoGenerator):
99
117
  def __init__(self, runtime: AsyncBithuman):
@@ -108,11 +126,11 @@ class BithumanGenerator(VideoGenerator):
108
126
 
109
127
  @property
110
128
  def video_fps(self) -> int:
111
- return self._runtime.settings.FPS
129
+ return self._runtime.settings.FPS # type: ignore
112
130
 
113
131
  @property
114
132
  def audio_sample_rate(self) -> int:
115
- return self._runtime.settings.INPUT_SAMPLE_RATE
133
+ return self._runtime.settings.INPUT_SAMPLE_RATE # type: ignore
116
134
 
117
135
  @utils.log_exceptions(logger=logger)
118
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.23"
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.23
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/
@@ -18,7 +18,7 @@ Classifier: Topic :: Multimedia :: Video
18
18
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
19
  Requires-Python: >=3.9.0
20
20
  Requires-Dist: bithuman>=0.5.10
21
- Requires-Dist: livekit-agents>=1.0.23
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=IlFtxJIXEN4SfEE6x7h78U2oCixHpndra7xIIdqT8Hw,5305
3
- livekit/plugins/bithuman/log.py,sha256=1lFUaugLdHDmBqFuNz2Z70iMRyuOtQ9KkL5h3ney0So,71
4
- livekit/plugins/bithuman/version.py,sha256=O5JviWLJVBpC-DAakcGUwagiTFI5ZD7HTTTp2woaBmo,601
5
- livekit_plugins_bithuman-1.0.23.dist-info/METADATA,sha256=V-abLhK_RT_xmF7qVwmEDAqq7qlj7yS0jVIq1yytR30,1180
6
- livekit_plugins_bithuman-1.0.23.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- livekit_plugins_bithuman-1.0.23.dist-info/RECORD,,