livekit-plugins-elevenlabs 0.7.0.dev2__py3-none-any.whl → 0.7.1__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.
@@ -101,9 +101,7 @@ class TTS(tts.TTS):
101
101
  word_tokenizer: tokenize.WordTokenizer = tokenize.basic.WordTokenizer(
102
102
  ignore_punctuation=False # punctuation can help for intonation
103
103
  ),
104
- # default value of 11labs is [120, 160, 250, 290], but we want faster responses by default
105
- # (range is 50-500)
106
- chunk_length_schedule: list[int] = [80, 120, 200, 260],
104
+ chunk_length_schedule: list[int] = [80, 120, 200, 260], # range is [50, 500]
107
105
  http_session: aiohttp.ClientSession | None = None,
108
106
  ) -> None:
109
107
  super().__init__(
@@ -208,8 +206,7 @@ class SynthesizeStream(tts.SynthesizeStream):
208
206
  opts: _TTSOptions,
209
207
  ):
210
208
  super().__init__()
211
- self._opts = opts
212
- self._session = session
209
+ self._opts, self._session = opts, session
213
210
  self._mp3_decoder = utils.codecs.Mp3StreamDecoder()
214
211
 
215
212
  @utils.log_exceptions(logger=logger)
@@ -222,31 +219,39 @@ class SynthesizeStream(tts.SynthesizeStream):
222
219
  word_stream = None
223
220
  async for input in self._input_ch:
224
221
  if isinstance(input, str):
225
- if not word_stream:
222
+ if word_stream is None:
223
+ # new segment (after flush for e.g)
226
224
  word_stream = self._opts.word_tokenizer.stream()
227
225
  self._segments_ch.send_nowait(word_stream)
228
226
 
229
227
  word_stream.push_text(input)
230
228
  elif isinstance(input, self._FlushSentinel):
231
- word_stream.end_input()
229
+ if word_stream is not None:
230
+ word_stream.end_input()
231
+
232
232
  word_stream = None
233
233
 
234
234
  self._segments_ch.close()
235
235
 
236
+ @utils.log_exceptions(logger=logger)
236
237
  async def _run():
237
238
  async for word_stream in self._segments_ch:
238
239
  await self._run_ws(word_stream)
239
240
 
240
- await asyncio.gather(_tokenize_input(), _run(), return_exceptions=True)
241
+ tasks = [
242
+ asyncio.create_task(_tokenize_input()),
243
+ asyncio.create_task(_run()),
244
+ ]
245
+ try:
246
+ await asyncio.gather(*tasks)
247
+ finally:
248
+ await utils.aio.gracefully_cancel(*tasks)
241
249
 
242
250
  async def _run_ws(
243
251
  self,
244
252
  word_stream: tokenize.WordStream,
245
- max_retry: int = 1,
253
+ max_retry: int = 3,
246
254
  ) -> None:
247
- request_id = utils.shortuuid()
248
- segment_id = utils.shortuuid()
249
-
250
255
  ws_conn: aiohttp.ClientWebSocketResponse | None = None
251
256
  for try_i in range(max_retry):
252
257
  retry_delay = 5
@@ -268,6 +273,10 @@ class SynthesizeStream(tts.SynthesizeStream):
268
273
  if ws_conn is None:
269
274
  raise Exception(f"failed to connect to 11labs after {max_retry} retries")
270
275
 
276
+ request_id = utils.shortuuid()
277
+ segment_id = utils.shortuuid()
278
+
279
+ # 11labs protocol expects the first message to be an "init msg"
271
280
  init_pkt = dict(
272
281
  text=" ",
273
282
  try_trigger_generation=True,
@@ -291,7 +300,6 @@ class SynthesizeStream(tts.SynthesizeStream):
291
300
  text=f"{data.token} ", # must always end with a space
292
301
  try_trigger_generation=False,
293
302
  )
294
- print(data_pkt)
295
303
  await ws_conn.send_str(json.dumps(data_pkt))
296
304
 
297
305
  # no more token, mark eos
@@ -300,6 +308,8 @@ class SynthesizeStream(tts.SynthesizeStream):
300
308
  eos_sent = True
301
309
 
302
310
  async def recv_task():
311
+ nonlocal eos_sent
312
+
303
313
  while True:
304
314
  msg = await ws_conn.receive()
305
315
  if msg.type in (
@@ -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.7.0-dev.2"
15
+ __version__ = "0.7.1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: livekit-plugins-elevenlabs
3
- Version: 0.7.0.dev2
3
+ Version: 0.7.1
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,7 +19,7 @@ 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-agents[codecs] >=0.7.2
22
+ Requires-Dist: livekit-agents[codecs] >=0.8.0.dev0
23
23
 
24
24
  # LiveKit Plugins Elevenlabs
25
25
 
@@ -0,0 +1,10 @@
1
+ livekit/plugins/elevenlabs/__init__.py,sha256=ez1ybDPt7GfKAKgPkxZFRB7Vyd-_i-0hfUMI79GQ5w4,1091
2
+ livekit/plugins/elevenlabs/log.py,sha256=hIuXqDsEB5GBa7rQY3z4Uqi1oCqc_lRmCHZEmXz0LHw,73
3
+ livekit/plugins/elevenlabs/models.py,sha256=8jTchztgpiTokHEaWUK8PPxWWfvm5SMrOGsJpzxbYAw,362
4
+ livekit/plugins/elevenlabs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ livekit/plugins/elevenlabs/tts.py,sha256=fEqtmbzvuJ0Pso0kzJ_37_2aCHES7W1kKUwTycLRGpM,13318
6
+ livekit/plugins/elevenlabs/version.py,sha256=JOBYrlKcxbTTRXkUKH0921GsmV-i71_KHczg2cgQiLc,600
7
+ livekit_plugins_elevenlabs-0.7.1.dist-info/METADATA,sha256=PuFr70N0Y4YzxtzkeMmxwnyLkrQbynCUN0YKFu6gQV0,1311
8
+ livekit_plugins_elevenlabs-0.7.1.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
9
+ livekit_plugins_elevenlabs-0.7.1.dist-info/top_level.txt,sha256=OoDok3xUmXbZRvOrfvvXB-Juu4DX79dlq188E19YHoo,8
10
+ livekit_plugins_elevenlabs-0.7.1.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- livekit/plugins/elevenlabs/__init__.py,sha256=ez1ybDPt7GfKAKgPkxZFRB7Vyd-_i-0hfUMI79GQ5w4,1091
2
- livekit/plugins/elevenlabs/log.py,sha256=hIuXqDsEB5GBa7rQY3z4Uqi1oCqc_lRmCHZEmXz0LHw,73
3
- livekit/plugins/elevenlabs/models.py,sha256=8jTchztgpiTokHEaWUK8PPxWWfvm5SMrOGsJpzxbYAw,362
4
- livekit/plugins/elevenlabs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- livekit/plugins/elevenlabs/tts.py,sha256=HpaHJQysUhThDdlYDHpQxroo9L2_m6G6QBAaNXs04K4,13032
6
- livekit/plugins/elevenlabs/version.py,sha256=LpPTO0u8YzF4Ep37Uh6FmXT3-n7H6OkH0IZmE0eXepE,606
7
- livekit_plugins_elevenlabs-0.7.0.dev2.dist-info/METADATA,sha256=ySSaOVf8y8acV-xWEQxWQPtuVWgduPShAyUkM0LiuBI,1311
8
- livekit_plugins_elevenlabs-0.7.0.dev2.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
9
- livekit_plugins_elevenlabs-0.7.0.dev2.dist-info/top_level.txt,sha256=OoDok3xUmXbZRvOrfvvXB-Juu4DX79dlq188E19YHoo,8
10
- livekit_plugins_elevenlabs-0.7.0.dev2.dist-info/RECORD,,