livekit-plugins-elevenlabs 0.1.5__py3-none-any.whl → 0.3.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.
@@ -12,8 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
-
16
- from .tts import TTS, Voice, VoiceSettings, DEFAULT_VOICE
15
+ from .tts import DEFAULT_VOICE, TTS, Voice, VoiceSettings
17
16
  from .version import __version__
18
17
 
19
18
  __all__ = ["TTS", "Voice", "VoiceSettings", "DEFAULT_VOICE", "__version__"]
@@ -23,7 +22,7 @@ from livekit.agents import Plugin
23
22
 
24
23
  class ElevenLabsPlugin(Plugin):
25
24
  def __init__(self):
26
- super().__init__(__name__, __version__)
25
+ super().__init__(__name__, __version__, __package__)
27
26
 
28
27
  def download_files(self):
29
28
  pass
File without changes
@@ -12,18 +12,20 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- import contextlib
16
15
  import asyncio
17
- import logging
18
16
  import base64
17
+ import contextlib
19
18
  import dataclasses
20
19
  import json
20
+ import logging
21
21
  import os
22
22
  from dataclasses import dataclass
23
- from typing import List, Optional
23
+ from typing import Any, AsyncIterable, Dict, List, Optional
24
+
24
25
  import aiohttp
25
26
  from livekit import rtc
26
27
  from livekit.agents import tts
28
+
27
29
  from .models import TTSModels
28
30
 
29
31
 
@@ -101,37 +103,40 @@ class TTS(tts.TTS):
101
103
  data = await resp.json()
102
104
  return dict_to_voices_list(data)
103
105
 
104
- async def synthesize(
106
+ def synthesize(
105
107
  self,
106
- *,
107
108
  text: str,
108
- ) -> tts.SynthesizedAudio:
109
+ ) -> AsyncIterable[tts.SynthesizedAudio]:
109
110
  voice = self._config.voice
110
- async with self._session.post(
111
- f"{self._config.base_url}/text-to-speech/{voice.id}?output_format=pcm_44100",
112
- headers={AUTHORIZATION_HEADER: self._config.api_key},
113
- json=dict(
114
- text=text,
115
- model_id=self._config.model_id,
116
- voice_settings=dataclasses.asdict(voice.settings)
117
- if voice.settings
118
- else None,
119
- ),
120
- ) as resp:
121
- data = await resp.read()
122
- return tts.SynthesizedAudio(
123
- text=text,
124
- data=rtc.AudioFrame(
125
- data=data,
126
- sample_rate=44100,
127
- num_channels=1,
128
- samples_per_channel=len(data) // 2, # 16-bit
111
+
112
+ async def generator():
113
+ async with self._session.post(
114
+ f"{self._config.base_url}/text-to-speech/{voice.id}?output_format=pcm_44100",
115
+ headers={AUTHORIZATION_HEADER: self._config.api_key},
116
+ json=dict(
117
+ text=text,
118
+ model_id=self._config.model_id,
119
+ voice_settings=dataclasses.asdict(voice.settings)
120
+ if voice.settings
121
+ else None,
129
122
  ),
130
- )
123
+ ) as resp:
124
+ data = await resp.read()
125
+ yield tts.SynthesizedAudio(
126
+ text=text,
127
+ data=rtc.AudioFrame(
128
+ data=data,
129
+ sample_rate=44100,
130
+ num_channels=1,
131
+ samples_per_channel=len(data) // 2, # 16-bit
132
+ ),
133
+ )
134
+
135
+ return generator()
131
136
 
132
137
  def stream(
133
138
  self,
134
- ) -> tts.SynthesizeStream:
139
+ ) -> "SynthesizeStream":
135
140
  return SynthesizeStream(self._session, self._config)
136
141
 
137
142
 
@@ -163,7 +168,7 @@ class SynthesizeStream(tts.SynthesizeStream):
163
168
  model_id = self._config.model_id
164
169
  return f"{base_url}/text-to-speech/{voice_id}/stream-input?model_id={model_id}&output_format=pcm_{self._config.sample_rate}&optimize_streaming_latency={self._config.latency}"
165
170
 
166
- def push_text(self, token: str) -> None:
171
+ def push_text(self, token: str | None) -> None:
167
172
  if self._closed:
168
173
  raise ValueError("cannot push to a closed stream")
169
174
 
@@ -283,9 +288,9 @@ class SynthesizeStream(tts.SynthesizeStream):
283
288
  if msg.type != aiohttp.WSMsgType.TEXT:
284
289
  continue
285
290
 
286
- msg = json.loads(msg.data)
287
- if msg.get("audio"):
288
- data = base64.b64decode(msg["audio"])
291
+ jsonMessage: Dict[str, Any] = json.loads(str(msg.data))
292
+ if jsonMessage.get("audio"):
293
+ data = base64.b64decode(jsonMessage["audio"])
289
294
  audio_frame = rtc.AudioFrame(
290
295
  data=data,
291
296
  sample_rate=self._config.sample_rate,
@@ -298,7 +303,7 @@ class SynthesizeStream(tts.SynthesizeStream):
298
303
  audio=tts.SynthesizedAudio(text="", data=audio_frame),
299
304
  )
300
305
  )
301
- elif msg.get("isFinal"):
306
+ elif jsonMessage.get("isFinal"):
302
307
  break
303
308
  else:
304
309
  logging.error(f"Unhandled message from ElevenLabs: {msg}")
@@ -309,7 +314,11 @@ class SynthesizeStream(tts.SynthesizeStream):
309
314
  self._queue.put_nowait(STREAM_EOS)
310
315
  await self._queue.join()
311
316
 
312
- async def aclose(self) -> None:
317
+ async def aclose(self, wait=False) -> None:
318
+ if wait:
319
+ logging.warning(
320
+ "wait=True is not yet supported for ElevenLabs TTS. Closing immediately."
321
+ )
313
322
  self._main_task.cancel()
314
323
  with contextlib.suppress(asyncio.CancelledError):
315
324
  await self._main_task
@@ -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__ = "0.1.5"
15
+ __version__ = "0.3.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: livekit-plugins-elevenlabs
3
- Version: 0.1.5
3
+ Version: 0.3.0
4
4
  Summary: Agent Framework plugin for voice synthesis with ElevenLabs' API.
5
5
  Home-page: https://github.com/livekit/agents
6
6
  License: Apache-2.0
@@ -19,8 +19,8 @@ Classifier: Programming Language :: Python :: 3.10
19
19
  Classifier: Programming Language :: Python :: 3 :: Only
20
20
  Requires-Python: >=3.9.0
21
21
  Description-Content-Type: text/markdown
22
- Requires-Dist: livekit >=0.8.0
23
- Requires-Dist: livekit-agents >=0.3.0
22
+ Requires-Dist: livekit ~=0.9
23
+ Requires-Dist: livekit-agents ~=0.5.dev0
24
24
  Requires-Dist: aiohttp >=3.8.5
25
25
 
26
26
  # LiveKit Plugins Elevenlabs
@@ -0,0 +1,9 @@
1
+ livekit/plugins/elevenlabs/__init__.py,sha256=_IMIfE4YA7d3NxrN-iCrdfQ19mwh93SY676RJGEA57c,989
2
+ livekit/plugins/elevenlabs/models.py,sha256=g46mCMMHP3x3qtHmybHHMcid1UwmjKCcF0T4IWjMjWE,163
3
+ livekit/plugins/elevenlabs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ livekit/plugins/elevenlabs/tts.py,sha256=hN9aRGQ_9B9ehnB7cS19gtZ3uHIa-28RPoIIRZrdm-w,11503
5
+ livekit/plugins/elevenlabs/version.py,sha256=G5iYozum4q7UpHwW43F7QfhzUfwcncPxBZ0gmUGsd5I,600
6
+ livekit_plugins_elevenlabs-0.3.0.dist-info/METADATA,sha256=vY-Re5myy-A_j253KS9MNz7LGmE2TL5Trr6q54JnegQ,1361
7
+ livekit_plugins_elevenlabs-0.3.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
8
+ livekit_plugins_elevenlabs-0.3.0.dist-info/top_level.txt,sha256=OoDok3xUmXbZRvOrfvvXB-Juu4DX79dlq188E19YHoo,8
9
+ livekit_plugins_elevenlabs-0.3.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: bdist_wheel (0.43.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,8 +0,0 @@
1
- livekit/plugins/elevenlabs/__init__.py,sha256=-FQ-hnTqqbaVFa0sEu8CwInVp9vzkt-nRWkd34ruFFk,977
2
- livekit/plugins/elevenlabs/models.py,sha256=g46mCMMHP3x3qtHmybHHMcid1UwmjKCcF0T4IWjMjWE,163
3
- livekit/plugins/elevenlabs/tts.py,sha256=L9k2jttTbkcv7qsKiamdR75MRGT3EfSQ7L6k-pkhDeY,11114
4
- livekit/plugins/elevenlabs/version.py,sha256=I8f9sRyhy7trGTK3-bCHGNvYPnJsNtV8zeYXa6iyQxc,600
5
- livekit_plugins_elevenlabs-0.1.5.dist-info/METADATA,sha256=bYrkpn7u9sFi9coZCC5-gMA0UA2xa64rtfM3lR2cz_A,1360
6
- livekit_plugins_elevenlabs-0.1.5.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
7
- livekit_plugins_elevenlabs-0.1.5.dist-info/top_level.txt,sha256=OoDok3xUmXbZRvOrfvvXB-Juu4DX79dlq188E19YHoo,8
8
- livekit_plugins_elevenlabs-0.1.5.dist-info/RECORD,,