cartesia 1.0.7__py2.py3-none-any.whl → 1.0.9__py2.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.
cartesia/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
- from cartesia.client import Cartesia, AsyncCartesia
1
+ from cartesia.client import AsyncCartesia, Cartesia
2
2
 
3
3
  __all__ = ["Cartesia", "AsyncCartesia"]
cartesia/_types.py CHANGED
@@ -1,4 +1,5 @@
1
1
  from typing import List, TypedDict
2
+
2
3
  from cartesia.utils.deprecated import deprecated
3
4
 
4
5
 
cartesia/client.py CHANGED
@@ -1,41 +1,47 @@
1
1
  import asyncio
2
2
  import base64
3
- from collections import defaultdict
4
3
  import json
4
+ import logging
5
5
  import os
6
6
  import uuid
7
+ from collections import defaultdict
7
8
  from types import TracebackType
8
9
  from typing import (
9
10
  Any,
10
11
  AsyncGenerator,
11
- Iterator,
12
+ Callable,
12
13
  Dict,
13
14
  Generator,
15
+ Iterator,
14
16
  List,
15
17
  Optional,
18
+ Set,
16
19
  Tuple,
17
20
  Union,
18
- Callable,
19
- Set,
20
21
  )
21
22
 
22
23
  import aiohttp
23
24
  import httpx
24
- import logging
25
25
  import requests
26
- from websockets.sync.client import connect
27
- from iterators import TimeoutIterator
28
26
 
29
- from cartesia.utils.retry import retry_on_connection_error, retry_on_connection_error_async
27
+ try:
28
+ from websockets.sync.client import connect
29
+
30
+ IS_WEBSOCKET_SYNC_AVAILABLE = True
31
+ except ImportError:
32
+ IS_WEBSOCKET_SYNC_AVAILABLE = False
33
+
30
34
  from cartesia._types import (
35
+ DeprecatedOutputFormatMapping,
31
36
  EventType,
32
37
  OutputFormat,
33
38
  OutputFormatMapping,
34
- DeprecatedOutputFormatMapping,
35
39
  VoiceControls,
36
40
  VoiceMetadata,
37
41
  )
38
-
42
+ from cartesia.utils.retry import retry_on_connection_error, retry_on_connection_error_async
43
+ from iterators import TimeoutIterator
44
+ from websockets.sync.client import connect
39
45
 
40
46
  DEFAULT_MODEL_ID = "sonic-english" # latest default model
41
47
  MULTILINGUAL_MODEL_ID = "sonic-multilingual" # latest multilingual model
@@ -207,38 +213,27 @@ class Voices(Resource):
207
213
 
208
214
  return response.json()
209
215
 
210
- def clone(self, filepath: Optional[str] = None, link: Optional[str] = None) -> List[float]:
211
- """Clone a voice from a clip or a URL.
216
+ def clone(self, filepath: Optional[str] = None, enhance: str = True) -> List[float]:
217
+ """Clone a voice from a clip.
212
218
 
213
219
  Args:
214
220
  filepath: The path to the clip file.
215
- link: The URL to the clip
221
+ enhance: Whether to enhance the clip before cloning the voice (highly recommended). Defaults to True.
216
222
 
217
223
  Returns:
218
224
  The embedding of the cloned voice as a list of floats.
219
225
  """
220
- # TODO: Python has a bytes object, use that instead of a filepath
221
- if not filepath and not link:
222
- raise ValueError("At least one of 'filepath' or 'link' must be specified.")
223
- if filepath and link:
224
- raise ValueError("Only one of 'filepath' or 'link' should be specified.")
225
- if filepath:
226
- url = f"{self._http_url()}/voices/clone/clip"
227
- with open(filepath, "rb") as file:
228
- files = {"clip": file}
229
- headers = self.headers.copy()
230
- headers.pop("Content-Type", None)
231
- response = httpx.post(url, headers=headers, files=files, timeout=self.timeout)
232
- if not response.is_success:
233
- raise ValueError(f"Failed to clone voice from clip. Error: {response.text}")
234
- elif link:
235
- url = f"{self._http_url()}/voices/clone/url"
236
- params = {"link": link}
226
+ if not filepath:
227
+ raise ValueError("Filepath must be specified.")
228
+ url = f"{self._http_url()}/voices/clone/clip"
229
+ with open(filepath, "rb") as file:
230
+ files = {"clip": file}
231
+ files["enhance"] = str(enhance).lower()
237
232
  headers = self.headers.copy()
238
- headers.pop("Content-Type") # The content type header is not required for URLs
239
- response = httpx.post(url, headers=self.headers, params=params, timeout=self.timeout)
233
+ headers.pop("Content-Type", None)
234
+ response = httpx.post(url, headers=headers, files=files, timeout=self.timeout)
240
235
  if not response.is_success:
241
- raise ValueError(f"Failed to clone voice from URL. Error: {response.text}")
236
+ raise ValueError(f"Failed to clone voice from clip. Error: {response.text}")
242
237
 
243
238
  return response.json()["embedding"]
244
239
 
@@ -469,6 +464,10 @@ class _WebSocket:
469
464
  Raises:
470
465
  RuntimeError: If the connection to the WebSocket fails.
471
466
  """
467
+ if not IS_WEBSOCKET_SYNC_AVAILABLE:
468
+ raise ImportError(
469
+ "The synchronous WebSocket client is not available. Please ensure that you have 'websockets>=12.0' or compatible version installed."
470
+ )
472
471
  if self.websocket is None or self._is_websocket_closed():
473
472
  route = "tts/websocket"
474
473
  try:
cartesia/utils/retry.py CHANGED
@@ -1,9 +1,9 @@
1
- import time
2
-
3
- from aiohttp.client_exceptions import ServerDisconnectedError
4
1
  import asyncio
2
+ import time
5
3
  from functools import wraps
6
4
  from http.client import RemoteDisconnected
5
+
6
+ from aiohttp.client_exceptions import ServerDisconnectedError
7
7
  from httpx import TimeoutException
8
8
  from requests.exceptions import ConnectionError
9
9
 
cartesia/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "1.0.7"
1
+ __version__ = "1.0.9"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cartesia
3
- Version: 1.0.7
3
+ Version: 1.0.9
4
4
  Summary: The official Python library for the Cartesia API.
5
5
  Home-page:
6
6
  Author: Cartesia, Inc.
@@ -43,6 +43,22 @@ The official Cartesia Python library which provides convenient access to the Car
43
43
  > [!IMPORTANT]
44
44
  > The client library introduces breaking changes in v1.0.0, which was released on June 24th 2024. See the [release notes](https://github.com/cartesia-ai/cartesia-python/releases/tag/v1.0.0) and [migration guide](https://github.com/cartesia-ai/cartesia-python/discussions/44). Reach out to us on [Discord](https://discord.gg/ZVxavqHB9X) for any support requests!
45
45
 
46
+ - [Cartesia Python API Library](#cartesia-python-api-library)
47
+ - [Documentation](#documentation)
48
+ - [Installation](#installation)
49
+ - [Voices](#voices)
50
+ - [Text-to-Speech](#text-to-speech)
51
+ - [Server-Sent Events (SSE)](#server-sent-events-sse)
52
+ - [WebSocket](#websocket)
53
+ - [Conditioning speech on previous generations using WebSocket](#conditioning-speech-on-previous-generations-using-websocket)
54
+ - [Generating timestamps using WebSocket](#generating-timestamps-using-websocket)
55
+ - [Multilingual Text-to-Speech \[Alpha\]](#multilingual-text-to-speech-alpha)
56
+ - [Speed and Emotion Control \[Experimental\]](#speed-and-emotion-control-experimental)
57
+ - [Jupyter Notebook Usage](#jupyter-notebook-usage)
58
+ - [Utility methods](#utility-methods)
59
+ - [Output Formats](#output-formats)
60
+
61
+
46
62
  ## Documentation
47
63
 
48
64
  Our complete API documentation can be found [on docs.cartesia.ai](https://docs.cartesia.ai).
@@ -268,7 +284,7 @@ async def send_transcripts(ctx):
268
284
 
269
285
  # You can check out our models at https://docs.cartesia.ai/getting-started/available-models
270
286
  model_id = "sonic-english"
271
-
287
+
272
288
  # You can find the supported `output_format`s at https://docs.cartesia.ai/api-reference/endpoints/stream-speech-server-sent-events
273
289
  output_format = {
274
290
  "container": "raw",
@@ -284,7 +300,7 @@ async def send_transcripts(ctx):
284
300
  "As they near Eggman's lair, our heroes charge their abilities for an epic boss battle. ",
285
301
  "Get ready to spin, jump, and sound-blast your way to victory in this high-octane crossover!"
286
302
  ]
287
-
303
+
288
304
  for transcript in transcripts:
289
305
  # Send text inputs as they become available
290
306
  await ctx.send(
@@ -296,7 +312,7 @@ async def send_transcripts(ctx):
296
312
  )
297
313
 
298
314
  # Indicate that no more inputs will be sent. Otherwise, the context will close after 5 seconds of inactivity.
299
- await ctx.no_more_inputs()
315
+ await ctx.no_more_inputs()
300
316
 
301
317
  async def receive_and_play_audio(ctx):
302
318
  p = pyaudio.PyAudio()
@@ -402,7 +418,7 @@ output_stream = ctx.send(
402
418
  voice_id=voice_id,
403
419
  output_format=output_format,
404
420
  )
405
-
421
+
406
422
  for output in output_stream:
407
423
  buffer = output["audio"]
408
424
 
@@ -0,0 +1,12 @@
1
+ cartesia/__init__.py,sha256=E4w7psbAwx8X6Iri3W8jGeo11gIlhr3mSU33zChipmI,93
2
+ cartesia/_types.py,sha256=rISSd6sfne6awLDoonqA9KlE0fVQZdIaGjxsvHTFBlE,4407
3
+ cartesia/client.py,sha256=m6eVIr5AL0Xuwh7707jXMNIxx1CAseW03xvgbbuNNsU,51613
4
+ cartesia/version.py,sha256=q2ACMkQx0Hm5xKo2YKJFBE7rTruciTSIN6AvWWL9nB8,22
5
+ cartesia/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ cartesia/utils/deprecated.py,sha256=2cXvGtrxhPeUZA5LWy2n_U5OFLDv7SHeFtzqhjSJGyk,1674
7
+ cartesia/utils/retry.py,sha256=O6fyVWpH9Su8c0Fwupl57xMt6JrwJ52txBwP3faUL7k,3339
8
+ cartesia-1.0.9.dist-info/LICENSE.md,sha256=PT2YG5wEtEX1TNDn5sXkUXqbn-neyr7cZenTxd40ql4,1074
9
+ cartesia-1.0.9.dist-info/METADATA,sha256=C2htRYPEJuve-EhP1R7dazFxnBSJrCTnESIIDBx5vBk,21137
10
+ cartesia-1.0.9.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
11
+ cartesia-1.0.9.dist-info/top_level.txt,sha256=rTX4HnnCegMxl1FK9czpVC7GAvf3SwDzPG65qP-BS4w,9
12
+ cartesia-1.0.9.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- cartesia/__init__.py,sha256=jMIf2O7dTGxvTA5AfXtmh1H_EGfMtQseR5wXrjNRbLs,93
2
- cartesia/_types.py,sha256=Lcp4GOot5UfI0EveDi2QdNALMo1rK4PwUrtMvW5P6vY,4406
3
- cartesia/client.py,sha256=1T_HboqHZO6wjUDYpuWI7igV-QF_cRL4DY7v4NDzApo,51871
4
- cartesia/version.py,sha256=BW7SWRpHoxuOQZ67pS20yog2LWYl-nK7-BEFBNrHGgA,22
5
- cartesia/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- cartesia/utils/deprecated.py,sha256=2cXvGtrxhPeUZA5LWy2n_U5OFLDv7SHeFtzqhjSJGyk,1674
7
- cartesia/utils/retry.py,sha256=nuwWRfu3MOVTxIQMLjYf6WLaxSlnu_GdE3QjTV0zisQ,3339
8
- cartesia-1.0.7.dist-info/LICENSE.md,sha256=PT2YG5wEtEX1TNDn5sXkUXqbn-neyr7cZenTxd40ql4,1074
9
- cartesia-1.0.7.dist-info/METADATA,sha256=vvU7-K0raiw4hmotlST5wi6uSnGiXjMpHxd2CIzvbMc,20336
10
- cartesia-1.0.7.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
11
- cartesia-1.0.7.dist-info/top_level.txt,sha256=rTX4HnnCegMxl1FK9czpVC7GAvf3SwDzPG65qP-BS4w,9
12
- cartesia-1.0.7.dist-info/RECORD,,