cartesia 1.4.0__tar.gz → 2.0.0a2__tar.gz

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.
Files changed (190) hide show
  1. cartesia-2.0.0a2/PKG-INFO +307 -0
  2. cartesia-2.0.0a2/README.md +274 -0
  3. cartesia-2.0.0a2/pyproject.toml +71 -0
  4. cartesia-2.0.0a2/src/cartesia/__init__.py +293 -0
  5. cartesia-2.0.0a2/src/cartesia/api_status/__init__.py +6 -0
  6. cartesia-2.0.0a2/src/cartesia/api_status/client.py +104 -0
  7. cartesia-2.0.0a2/src/cartesia/api_status/requests/__init__.py +5 -0
  8. cartesia-2.0.0a2/src/cartesia/api_status/requests/api_info.py +8 -0
  9. cartesia-2.0.0a2/src/cartesia/api_status/types/__init__.py +5 -0
  10. cartesia-2.0.0a2/src/cartesia/api_status/types/api_info.py +20 -0
  11. cartesia-2.0.0a2/src/cartesia/base_client.py +160 -0
  12. cartesia-2.0.0a2/src/cartesia/client.py +192 -0
  13. cartesia-2.0.0a2/src/cartesia/core/__init__.py +47 -0
  14. cartesia-2.0.0a2/src/cartesia/core/api_error.py +15 -0
  15. cartesia-2.0.0a2/src/cartesia/core/client_wrapper.py +55 -0
  16. cartesia-2.0.0a2/src/cartesia/core/datetime_utils.py +28 -0
  17. cartesia-2.0.0a2/src/cartesia/core/file.py +67 -0
  18. cartesia-2.0.0a2/src/cartesia/core/http_client.py +499 -0
  19. cartesia-2.0.0a2/src/cartesia/core/jsonable_encoder.py +101 -0
  20. cartesia-2.0.0a2/src/cartesia/core/pydantic_utilities.py +296 -0
  21. cartesia-2.0.0a2/src/cartesia/core/query_encoder.py +58 -0
  22. cartesia-2.0.0a2/src/cartesia/core/remove_none_from_dict.py +11 -0
  23. cartesia-2.0.0a2/src/cartesia/core/request_options.py +35 -0
  24. cartesia-2.0.0a2/src/cartesia/core/serialization.py +272 -0
  25. cartesia-2.0.0a2/src/cartesia/datasets/__init__.py +24 -0
  26. cartesia-2.0.0a2/src/cartesia/datasets/client.py +392 -0
  27. cartesia-2.0.0a2/src/cartesia/datasets/requests/__init__.py +15 -0
  28. cartesia-2.0.0a2/src/cartesia/datasets/requests/create_dataset_request.py +7 -0
  29. cartesia-2.0.0a2/src/cartesia/datasets/requests/dataset.py +9 -0
  30. cartesia-2.0.0a2/src/cartesia/datasets/requests/dataset_file.py +9 -0
  31. cartesia-2.0.0a2/src/cartesia/datasets/requests/paginated_dataset_files.py +10 -0
  32. cartesia-2.0.0a2/src/cartesia/datasets/requests/paginated_datasets.py +10 -0
  33. cartesia-2.0.0a2/src/cartesia/datasets/types/__init__.py +17 -0
  34. cartesia-2.0.0a2/src/cartesia/datasets/types/create_dataset_request.py +19 -0
  35. cartesia-2.0.0a2/src/cartesia/datasets/types/dataset.py +21 -0
  36. cartesia-2.0.0a2/src/cartesia/datasets/types/dataset_file.py +21 -0
  37. cartesia-2.0.0a2/src/cartesia/datasets/types/file_purpose.py +5 -0
  38. cartesia-2.0.0a2/src/cartesia/datasets/types/paginated_dataset_files.py +21 -0
  39. cartesia-2.0.0a2/src/cartesia/datasets/types/paginated_datasets.py +21 -0
  40. cartesia-2.0.0a2/src/cartesia/embedding/__init__.py +5 -0
  41. cartesia-2.0.0a2/src/cartesia/embedding/types/__init__.py +5 -0
  42. cartesia-2.0.0a2/src/cartesia/embedding/types/embedding.py +201 -0
  43. cartesia-2.0.0a2/src/cartesia/environment.py +7 -0
  44. cartesia-2.0.0a2/src/cartesia/infill/__init__.py +2 -0
  45. cartesia-2.0.0a2/src/cartesia/infill/client.py +318 -0
  46. cartesia-2.0.0a2/src/cartesia/tts/__init__.py +167 -0
  47. {cartesia-1.4.0/cartesia → cartesia-2.0.0a2/src/cartesia/tts}/_async_websocket.py +159 -84
  48. cartesia-2.0.0a2/src/cartesia/tts/_websocket.py +430 -0
  49. cartesia-2.0.0a2/src/cartesia/tts/client.py +407 -0
  50. cartesia-2.0.0a2/src/cartesia/tts/requests/__init__.py +76 -0
  51. cartesia-2.0.0a2/src/cartesia/tts/requests/cancel_context_request.py +17 -0
  52. cartesia-2.0.0a2/src/cartesia/tts/requests/controls.py +11 -0
  53. cartesia-2.0.0a2/src/cartesia/tts/requests/generation_request.py +53 -0
  54. cartesia-2.0.0a2/src/cartesia/tts/requests/mp_3_output_format.py +11 -0
  55. cartesia-2.0.0a2/src/cartesia/tts/requests/output_format.py +30 -0
  56. cartesia-2.0.0a2/src/cartesia/tts/requests/phoneme_timestamps.py +10 -0
  57. cartesia-2.0.0a2/src/cartesia/tts/requests/raw_output_format.py +11 -0
  58. cartesia-2.0.0a2/src/cartesia/tts/requests/speed.py +7 -0
  59. cartesia-2.0.0a2/src/cartesia/tts/requests/tts_request.py +24 -0
  60. cartesia-2.0.0a2/src/cartesia/tts/requests/tts_request_embedding_specifier.py +16 -0
  61. cartesia-2.0.0a2/src/cartesia/tts/requests/tts_request_id_specifier.py +16 -0
  62. cartesia-2.0.0a2/src/cartesia/tts/requests/tts_request_voice_specifier.py +7 -0
  63. cartesia-2.0.0a2/src/cartesia/tts/requests/wav_output_format.py +7 -0
  64. cartesia-2.0.0a2/src/cartesia/tts/requests/web_socket_base_response.py +11 -0
  65. cartesia-2.0.0a2/src/cartesia/tts/requests/web_socket_chunk_response.py +8 -0
  66. cartesia-2.0.0a2/src/cartesia/tts/requests/web_socket_done_response.py +7 -0
  67. cartesia-2.0.0a2/src/cartesia/tts/requests/web_socket_error_response.py +7 -0
  68. cartesia-2.0.0a2/src/cartesia/tts/requests/web_socket_flush_done_response.py +9 -0
  69. cartesia-2.0.0a2/src/cartesia/tts/requests/web_socket_phoneme_timestamps_response.py +9 -0
  70. cartesia-2.0.0a2/src/cartesia/tts/requests/web_socket_raw_output_format.py +11 -0
  71. cartesia-2.0.0a2/src/cartesia/tts/requests/web_socket_request.py +7 -0
  72. cartesia-2.0.0a2/src/cartesia/tts/requests/web_socket_response.py +69 -0
  73. cartesia-2.0.0a2/src/cartesia/tts/requests/web_socket_stream_options.py +8 -0
  74. cartesia-2.0.0a2/src/cartesia/tts/requests/web_socket_timestamps_response.py +9 -0
  75. cartesia-2.0.0a2/src/cartesia/tts/requests/web_socket_tts_output.py +18 -0
  76. cartesia-2.0.0a2/src/cartesia/tts/requests/web_socket_tts_request.py +24 -0
  77. cartesia-2.0.0a2/src/cartesia/tts/requests/word_timestamps.py +10 -0
  78. cartesia-2.0.0a2/src/cartesia/tts/socket_client.py +302 -0
  79. cartesia-2.0.0a2/src/cartesia/tts/types/__init__.py +90 -0
  80. cartesia-2.0.0a2/src/cartesia/tts/types/cancel_context_request.py +28 -0
  81. cartesia-2.0.0a2/src/cartesia/tts/types/context_id.py +3 -0
  82. cartesia-2.0.0a2/src/cartesia/tts/types/controls.py +22 -0
  83. cartesia-2.0.0a2/src/cartesia/tts/types/emotion.py +29 -0
  84. cartesia-2.0.0a2/src/cartesia/tts/types/flush_id.py +3 -0
  85. cartesia-2.0.0a2/src/cartesia/tts/types/generation_request.py +66 -0
  86. cartesia-2.0.0a2/src/cartesia/tts/types/mp_3_output_format.py +23 -0
  87. cartesia-2.0.0a2/src/cartesia/tts/types/natural_specifier.py +5 -0
  88. cartesia-2.0.0a2/src/cartesia/tts/types/numerical_specifier.py +3 -0
  89. cartesia-2.0.0a2/src/cartesia/tts/types/output_format.py +58 -0
  90. cartesia-2.0.0a2/src/cartesia/tts/types/phoneme_timestamps.py +21 -0
  91. cartesia-2.0.0a2/src/cartesia/tts/types/raw_encoding.py +5 -0
  92. cartesia-2.0.0a2/src/cartesia/tts/types/raw_output_format.py +22 -0
  93. cartesia-2.0.0a2/src/cartesia/tts/types/speed.py +7 -0
  94. cartesia-2.0.0a2/src/cartesia/tts/types/supported_language.py +7 -0
  95. cartesia-2.0.0a2/src/cartesia/tts/types/tts_request.py +35 -0
  96. cartesia-2.0.0a2/src/cartesia/tts/types/tts_request_embedding_specifier.py +27 -0
  97. cartesia-2.0.0a2/src/cartesia/tts/types/tts_request_id_specifier.py +27 -0
  98. cartesia-2.0.0a2/src/cartesia/tts/types/tts_request_voice_specifier.py +7 -0
  99. cartesia-2.0.0a2/src/cartesia/tts/types/wav_output_format.py +17 -0
  100. cartesia-2.0.0a2/src/cartesia/tts/types/web_socket_base_response.py +22 -0
  101. cartesia-2.0.0a2/src/cartesia/tts/types/web_socket_chunk_response.py +20 -0
  102. cartesia-2.0.0a2/src/cartesia/tts/types/web_socket_done_response.py +17 -0
  103. cartesia-2.0.0a2/src/cartesia/tts/types/web_socket_error_response.py +19 -0
  104. cartesia-2.0.0a2/src/cartesia/tts/types/web_socket_flush_done_response.py +21 -0
  105. cartesia-2.0.0a2/src/cartesia/tts/types/web_socket_phoneme_timestamps_response.py +20 -0
  106. cartesia-2.0.0a2/src/cartesia/tts/types/web_socket_raw_output_format.py +22 -0
  107. cartesia-2.0.0a2/src/cartesia/tts/types/web_socket_request.py +7 -0
  108. cartesia-2.0.0a2/src/cartesia/tts/types/web_socket_response.py +124 -0
  109. cartesia-2.0.0a2/src/cartesia/tts/types/web_socket_stream_options.py +19 -0
  110. cartesia-2.0.0a2/src/cartesia/tts/types/web_socket_timestamps_response.py +20 -0
  111. cartesia-2.0.0a2/src/cartesia/tts/types/web_socket_tts_output.py +27 -0
  112. cartesia-2.0.0a2/src/cartesia/tts/types/web_socket_tts_request.py +36 -0
  113. cartesia-2.0.0a2/src/cartesia/tts/types/word_timestamps.py +21 -0
  114. cartesia-2.0.0a2/src/cartesia/tts/utils/tts.py +64 -0
  115. cartesia-2.0.0a2/src/cartesia/tts/utils/types.py +70 -0
  116. cartesia-2.0.0a2/src/cartesia/version.py +3 -0
  117. cartesia-2.0.0a2/src/cartesia/voice_changer/__init__.py +27 -0
  118. cartesia-2.0.0a2/src/cartesia/voice_changer/client.py +395 -0
  119. cartesia-2.0.0a2/src/cartesia/voice_changer/requests/__init__.py +15 -0
  120. cartesia-2.0.0a2/src/cartesia/voice_changer/requests/streaming_response.py +36 -0
  121. cartesia-2.0.0a2/src/cartesia/voice_changer/types/__init__.py +17 -0
  122. cartesia-2.0.0a2/src/cartesia/voice_changer/types/output_format_container.py +5 -0
  123. cartesia-2.0.0a2/src/cartesia/voice_changer/types/streaming_response.py +62 -0
  124. cartesia-2.0.0a2/src/cartesia/voices/__init__.py +71 -0
  125. cartesia-2.0.0a2/src/cartesia/voices/client.py +1053 -0
  126. cartesia-2.0.0a2/src/cartesia/voices/requests/__init__.py +27 -0
  127. cartesia-2.0.0a2/src/cartesia/voices/requests/create_voice_request.py +23 -0
  128. cartesia-2.0.0a2/src/cartesia/voices/requests/embedding_response.py +8 -0
  129. cartesia-2.0.0a2/src/cartesia/voices/requests/embedding_specifier.py +10 -0
  130. cartesia-2.0.0a2/src/cartesia/voices/requests/id_specifier.py +10 -0
  131. cartesia-2.0.0a2/src/cartesia/voices/requests/localize_dialect.py +8 -0
  132. cartesia-2.0.0a2/src/cartesia/voices/requests/localize_voice_request.py +15 -0
  133. cartesia-2.0.0a2/src/cartesia/voices/requests/mix_voice_specifier.py +7 -0
  134. cartesia-2.0.0a2/src/cartesia/voices/requests/mix_voices_request.py +9 -0
  135. cartesia-2.0.0a2/src/cartesia/voices/requests/update_voice_request.py +15 -0
  136. cartesia-2.0.0a2/src/cartesia/voices/requests/voice.py +39 -0
  137. cartesia-2.0.0a2/src/cartesia/voices/requests/voice_metadata.py +36 -0
  138. cartesia-2.0.0a2/src/cartesia/voices/types/__init__.py +45 -0
  139. cartesia-2.0.0a2/src/cartesia/voices/types/base_voice_id.py +5 -0
  140. cartesia-2.0.0a2/src/cartesia/voices/types/clone_mode.py +5 -0
  141. cartesia-2.0.0a2/src/cartesia/voices/types/create_voice_request.py +34 -0
  142. cartesia-2.0.0a2/src/cartesia/voices/types/embedding_response.py +20 -0
  143. cartesia-2.0.0a2/src/cartesia/voices/types/embedding_specifier.py +22 -0
  144. cartesia-2.0.0a2/src/cartesia/voices/types/gender.py +5 -0
  145. cartesia-2.0.0a2/src/cartesia/voices/types/id_specifier.py +22 -0
  146. cartesia-2.0.0a2/src/cartesia/voices/types/localize_dialect.py +8 -0
  147. cartesia-2.0.0a2/src/cartesia/voices/types/localize_english_dialect.py +5 -0
  148. cartesia-2.0.0a2/src/cartesia/voices/types/localize_portuguese_dialect.py +5 -0
  149. cartesia-2.0.0a2/src/cartesia/voices/types/localize_spanish_dialect.py +5 -0
  150. cartesia-2.0.0a2/src/cartesia/voices/types/localize_target_language.py +7 -0
  151. cartesia-2.0.0a2/src/cartesia/voices/types/localize_voice_request.py +26 -0
  152. cartesia-2.0.0a2/src/cartesia/voices/types/mix_voice_specifier.py +7 -0
  153. cartesia-2.0.0a2/src/cartesia/voices/types/mix_voices_request.py +20 -0
  154. cartesia-2.0.0a2/src/cartesia/voices/types/update_voice_request.py +27 -0
  155. cartesia-2.0.0a2/src/cartesia/voices/types/voice.py +50 -0
  156. cartesia-2.0.0a2/src/cartesia/voices/types/voice_id.py +3 -0
  157. cartesia-2.0.0a2/src/cartesia/voices/types/voice_metadata.py +48 -0
  158. cartesia-2.0.0a2/src/cartesia/voices/types/weight.py +3 -0
  159. cartesia-1.4.0/.github/workflows/ci.yaml +0 -64
  160. cartesia-1.4.0/.github/workflows/publish.yaml +0 -58
  161. cartesia-1.4.0/.gitignore +0 -60
  162. cartesia-1.4.0/LICENSE.md +0 -21
  163. cartesia-1.4.0/Makefile +0 -13
  164. cartesia-1.4.0/PKG-INFO +0 -663
  165. cartesia-1.4.0/README.md +0 -649
  166. cartesia-1.4.0/bumpversion.py +0 -41
  167. cartesia-1.4.0/cartesia/__init__.py +0 -4
  168. cartesia-1.4.0/cartesia/_async_sse.py +0 -95
  169. cartesia-1.4.0/cartesia/_logger.py +0 -3
  170. cartesia-1.4.0/cartesia/_sse.py +0 -143
  171. cartesia-1.4.0/cartesia/_types.py +0 -70
  172. cartesia-1.4.0/cartesia/_websocket.py +0 -358
  173. cartesia-1.4.0/cartesia/async_client.py +0 -82
  174. cartesia-1.4.0/cartesia/async_tts.py +0 -176
  175. cartesia-1.4.0/cartesia/client.py +0 -69
  176. cartesia-1.4.0/cartesia/resource.py +0 -44
  177. cartesia-1.4.0/cartesia/tts.py +0 -292
  178. cartesia-1.4.0/cartesia/utils/deprecated.py +0 -55
  179. cartesia-1.4.0/cartesia/utils/retry.py +0 -87
  180. cartesia-1.4.0/cartesia/utils/tts.py +0 -78
  181. cartesia-1.4.0/cartesia/version.py +0 -1
  182. cartesia-1.4.0/cartesia/voices.py +0 -204
  183. cartesia-1.4.0/pyproject.toml +0 -89
  184. cartesia-1.4.0/tests/__init__.py +0 -0
  185. cartesia-1.4.0/tests/resources/sample-speech-4s.wav +0 -0
  186. cartesia-1.4.0/tests/test_deprecated.py +0 -20
  187. cartesia-1.4.0/tests/test_tts.py +0 -1152
  188. cartesia-1.4.0/uv.lock +0 -1465
  189. /cartesia-1.4.0/cartesia/utils/__init__.py → /cartesia-2.0.0a2/src/cartesia/py.typed +0 -0
  190. /cartesia-1.4.0/cartesia/_constants.py → /cartesia-2.0.0a2/src/cartesia/tts/utils/constants.py +0 -0
@@ -0,0 +1,307 @@
1
+ Metadata-Version: 2.1
2
+ Name: cartesia
3
+ Version: 2.0.0a2
4
+ Summary:
5
+ Requires-Python: >=3.8,<4.0
6
+ Classifier: Intended Audience :: Developers
7
+ Classifier: Operating System :: MacOS
8
+ Classifier: Operating System :: Microsoft :: Windows
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Operating System :: POSIX
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Typing :: Typed
21
+ Requires-Dist: aiohttp (>=3.10.10)
22
+ Requires-Dist: audioop-lts (==0.2.1) ; python_version >= "3.13" and python_version < "4.0"
23
+ Requires-Dist: httpx (>=0.21.2)
24
+ Requires-Dist: httpx-sse (==0.4.0)
25
+ Requires-Dist: iterators (>=0.2.0)
26
+ Requires-Dist: pydantic (>=1.9.2)
27
+ Requires-Dist: pydantic-core (>=2.18.2,<3.0.0)
28
+ Requires-Dist: pydub (>=0.25.1)
29
+ Requires-Dist: typing_extensions (>=4.0.0)
30
+ Requires-Dist: websockets (>=10.4)
31
+ Description-Content-Type: text/markdown
32
+
33
+ # Cartesia Python Library
34
+
35
+ [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fcartesia-ai%2Fcartesia-python)
36
+ [![pypi](https://img.shields.io/pypi/v/cartesia)](https://pypi.python.org/pypi/cartesia)
37
+
38
+ The Cartesia Python library provides convenient access to the Cartesia API from Python.
39
+
40
+ ## Documentation
41
+
42
+ Our complete API documentation can be found [on docs.cartesia.ai](https://docs.cartesia.ai).
43
+
44
+ ## Installation
45
+
46
+ ```sh
47
+ pip install cartesia
48
+ ```
49
+
50
+ ## Reference
51
+
52
+ A full reference for this library is available [here](./reference.md).
53
+
54
+ ## Voices
55
+
56
+ ```python
57
+ from cartesia import Cartesia
58
+ import os
59
+
60
+ client = Cartesia(api_key=os.environ.get("CARTESIA_API_KEY"))
61
+
62
+ # Get all available voices
63
+ voices = client.voices.list()
64
+ print(voices)
65
+
66
+ # Get a specific voice
67
+ voice = client.voices.get(id="a0e99841-438c-4a64-b679-ae501e7d6091")
68
+ print("The embedding for", voice["name"], "is", voice["embedding"])
69
+
70
+ # Clone a voice using filepath
71
+ cloned_voice_embedding = client.voices.clone(filepath="path/to/voice")
72
+
73
+ # Mix voices together
74
+ mixed_voice_embedding = client.voices.mix(
75
+ [{ "id": "voice_id_1", "weight": 0.5 }, { "id": "voice_id_2", "weight": 0.25 }, { "id": "voice_id_3", "weight": 0.25 }]
76
+ )
77
+
78
+ # Create a new voice
79
+ new_voice = client.voices.create(
80
+ name="New Voice",
81
+ description="A clone of my own voice",
82
+ embedding=cloned_voice_embedding,
83
+ )
84
+ ```
85
+
86
+ ## Usage
87
+
88
+ Instantiate and use the client with the following:
89
+
90
+ ```python
91
+ from cartesia import Cartesia
92
+ from cartesia.tts import OutputFormat_Raw, TtsRequestIdSpecifier
93
+
94
+ client = Cartesia(
95
+ api_key="YOUR_API_KEY",
96
+ )
97
+ client.tts.bytes(
98
+ model_id="sonic-english",
99
+ transcript="Hello, world!",
100
+ voice={"id": "694f9389-aac1-45b6-b726-9d9369183238"},
101
+ ),
102
+ language="en",
103
+ output_format={
104
+ "container": "raw",
105
+ "sample_rate": 44100,
106
+ "encoding": "pcm_f32le",
107
+ },
108
+ )
109
+ ```
110
+
111
+ ## Async Client
112
+
113
+ The SDK also exports an `async` client so that you can make non-blocking calls to our API.
114
+
115
+ ```python
116
+ import asyncio
117
+
118
+ from cartesia import AsyncCartesia
119
+ from cartesia.tts import OutputFormat_Raw, TtsRequestIdSpecifier
120
+
121
+ client = AsyncCartesia(
122
+ api_key="YOUR_API_KEY",
123
+ )
124
+
125
+
126
+ async def main() -> None:
127
+ await client.tts.bytes(
128
+ model_id="sonic-english",
129
+ transcript="Hello, world!",
130
+ voice={"id": "694f9389-aac1-45b6-b726-9d9369183238"},
131
+ language="en",
132
+ output_format={
133
+ "container": "raw",
134
+ "sample_rate": 44100,
135
+ "encoding": "pcm_f32le",
136
+ },
137
+ )
138
+
139
+
140
+ asyncio.run(main())
141
+ ```
142
+
143
+ ## Exception Handling
144
+
145
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
146
+ will be thrown.
147
+
148
+ ```python
149
+ from cartesia.core.api_error import ApiError
150
+
151
+ try:
152
+ client.tts.bytes(...)
153
+ except ApiError as e:
154
+ print(e.status_code)
155
+ print(e.body)
156
+ ```
157
+
158
+ ## Streaming
159
+
160
+ The SDK supports streaming responses, as well, the response will be a generator that you can loop over.
161
+
162
+ ```python
163
+ from cartesia import Cartesia
164
+ from cartesia.tts import Controls, OutputFormat_RawParams, TtsRequestIdSpecifierParams
165
+
166
+ client = Cartesia(
167
+ api_key="YOUR_API_KEY",
168
+ )
169
+ response = client.tts.sse(
170
+ model_id="string",
171
+ transcript="string",
172
+ voice={
173
+ "id": "string",
174
+ "experimental_controls": {
175
+ speed=1.1,
176
+ emotion="anger:lowest",
177
+ },
178
+ },
179
+ language="en",
180
+ output_format={},
181
+ duration=1.1,
182
+ )
183
+ for chunk in response:
184
+ yield chunk
185
+ ```
186
+
187
+ ## WebSocket
188
+
189
+ ```python
190
+ from cartesia import Cartesia
191
+ from cartesia.tts import TtsRequestEmbeddingSpecifierParams, OutputFormat_RawParams
192
+ import pyaudio
193
+
194
+ client = Cartesia(
195
+ api_key="YOUR_API_KEY",
196
+ )
197
+ voice_id = "a0e99841-438c-4a64-b679-ae501e7d6091"
198
+ voice = client.voices.get(id=voice_id)
199
+ transcript = "Hello! Welcome to Cartesia"
200
+
201
+ # You can check out our models at https://docs.cartesia.ai/getting-started/available-models
202
+ model_id = "sonic-english"
203
+
204
+ p = pyaudio.PyAudio()
205
+ rate = 22050
206
+
207
+ stream = None
208
+
209
+ # Set up the websocket connection
210
+ ws = client.tts.websocket()
211
+
212
+ # Generate and stream audio using the websocket
213
+ for output in ws.send(
214
+ model_id=model_id,
215
+ transcript=transcript,
216
+ voice={"embedding": voice.embedding},
217
+ stream=True,
218
+ output_format={
219
+ "container": "raw",
220
+ "encoding": "pcm_f32le",
221
+ "sample_rate": 22050
222
+ },
223
+ ):
224
+ buffer = output.audio
225
+
226
+ if not stream:
227
+ stream = p.open(format=pyaudio.paFloat32, channels=1, rate=rate, output=True)
228
+
229
+ # Write the audio data to the stream
230
+ stream.write(buffer)
231
+
232
+ stream.stop_stream()
233
+ stream.close()
234
+ p.terminate()
235
+
236
+ ws.close() # Close the websocket connection
237
+ ```
238
+
239
+ ## Advanced
240
+
241
+ ### Retries
242
+
243
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
244
+ as the request is deemed retriable and the number of retry attempts has not grown larger than the configured
245
+ retry limit (default: 2).
246
+
247
+ A request is deemed retriable when any of the following HTTP status codes is returned:
248
+
249
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
250
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
251
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
252
+
253
+ Use the `max_retries` request option to configure this behavior.
254
+
255
+ ```python
256
+ client.tts.bytes(..., request_options={
257
+ "max_retries": 1
258
+ })
259
+ ```
260
+
261
+ ### Timeouts
262
+
263
+ The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
264
+
265
+ ```python
266
+
267
+ from cartesia import Cartesia
268
+
269
+ client = Cartesia(
270
+ ...,
271
+ timeout=20.0,
272
+ )
273
+
274
+
275
+ # Override timeout for a specific method
276
+ client.tts.bytes(..., request_options={
277
+ "timeout_in_seconds": 1
278
+ })
279
+ ```
280
+
281
+ ### Custom Client
282
+
283
+ You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
284
+ and transports.
285
+ ```python
286
+ import httpx
287
+ from cartesia import Cartesia
288
+
289
+ client = Cartesia(
290
+ ...,
291
+ httpx_client=httpx.Client(
292
+ proxies="http://my.test.proxy.example.com",
293
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
294
+ ),
295
+ )
296
+ ```
297
+
298
+ ## Contributing
299
+
300
+ While we value open-source contributions to this SDK, this library is generated programmatically.
301
+ Additions made directly to this library would have to be moved over to our generation code,
302
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
303
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
304
+ an issue first to discuss with us!
305
+
306
+ On the other hand, contributions to the README are always very welcome!
307
+
@@ -0,0 +1,274 @@
1
+ # Cartesia Python Library
2
+
3
+ [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fcartesia-ai%2Fcartesia-python)
4
+ [![pypi](https://img.shields.io/pypi/v/cartesia)](https://pypi.python.org/pypi/cartesia)
5
+
6
+ The Cartesia Python library provides convenient access to the Cartesia API from Python.
7
+
8
+ ## Documentation
9
+
10
+ Our complete API documentation can be found [on docs.cartesia.ai](https://docs.cartesia.ai).
11
+
12
+ ## Installation
13
+
14
+ ```sh
15
+ pip install cartesia
16
+ ```
17
+
18
+ ## Reference
19
+
20
+ A full reference for this library is available [here](./reference.md).
21
+
22
+ ## Voices
23
+
24
+ ```python
25
+ from cartesia import Cartesia
26
+ import os
27
+
28
+ client = Cartesia(api_key=os.environ.get("CARTESIA_API_KEY"))
29
+
30
+ # Get all available voices
31
+ voices = client.voices.list()
32
+ print(voices)
33
+
34
+ # Get a specific voice
35
+ voice = client.voices.get(id="a0e99841-438c-4a64-b679-ae501e7d6091")
36
+ print("The embedding for", voice["name"], "is", voice["embedding"])
37
+
38
+ # Clone a voice using filepath
39
+ cloned_voice_embedding = client.voices.clone(filepath="path/to/voice")
40
+
41
+ # Mix voices together
42
+ mixed_voice_embedding = client.voices.mix(
43
+ [{ "id": "voice_id_1", "weight": 0.5 }, { "id": "voice_id_2", "weight": 0.25 }, { "id": "voice_id_3", "weight": 0.25 }]
44
+ )
45
+
46
+ # Create a new voice
47
+ new_voice = client.voices.create(
48
+ name="New Voice",
49
+ description="A clone of my own voice",
50
+ embedding=cloned_voice_embedding,
51
+ )
52
+ ```
53
+
54
+ ## Usage
55
+
56
+ Instantiate and use the client with the following:
57
+
58
+ ```python
59
+ from cartesia import Cartesia
60
+ from cartesia.tts import OutputFormat_Raw, TtsRequestIdSpecifier
61
+
62
+ client = Cartesia(
63
+ api_key="YOUR_API_KEY",
64
+ )
65
+ client.tts.bytes(
66
+ model_id="sonic-english",
67
+ transcript="Hello, world!",
68
+ voice={"id": "694f9389-aac1-45b6-b726-9d9369183238"},
69
+ ),
70
+ language="en",
71
+ output_format={
72
+ "container": "raw",
73
+ "sample_rate": 44100,
74
+ "encoding": "pcm_f32le",
75
+ },
76
+ )
77
+ ```
78
+
79
+ ## Async Client
80
+
81
+ The SDK also exports an `async` client so that you can make non-blocking calls to our API.
82
+
83
+ ```python
84
+ import asyncio
85
+
86
+ from cartesia import AsyncCartesia
87
+ from cartesia.tts import OutputFormat_Raw, TtsRequestIdSpecifier
88
+
89
+ client = AsyncCartesia(
90
+ api_key="YOUR_API_KEY",
91
+ )
92
+
93
+
94
+ async def main() -> None:
95
+ await client.tts.bytes(
96
+ model_id="sonic-english",
97
+ transcript="Hello, world!",
98
+ voice={"id": "694f9389-aac1-45b6-b726-9d9369183238"},
99
+ language="en",
100
+ output_format={
101
+ "container": "raw",
102
+ "sample_rate": 44100,
103
+ "encoding": "pcm_f32le",
104
+ },
105
+ )
106
+
107
+
108
+ asyncio.run(main())
109
+ ```
110
+
111
+ ## Exception Handling
112
+
113
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
114
+ will be thrown.
115
+
116
+ ```python
117
+ from cartesia.core.api_error import ApiError
118
+
119
+ try:
120
+ client.tts.bytes(...)
121
+ except ApiError as e:
122
+ print(e.status_code)
123
+ print(e.body)
124
+ ```
125
+
126
+ ## Streaming
127
+
128
+ The SDK supports streaming responses, as well, the response will be a generator that you can loop over.
129
+
130
+ ```python
131
+ from cartesia import Cartesia
132
+ from cartesia.tts import Controls, OutputFormat_RawParams, TtsRequestIdSpecifierParams
133
+
134
+ client = Cartesia(
135
+ api_key="YOUR_API_KEY",
136
+ )
137
+ response = client.tts.sse(
138
+ model_id="string",
139
+ transcript="string",
140
+ voice={
141
+ "id": "string",
142
+ "experimental_controls": {
143
+ speed=1.1,
144
+ emotion="anger:lowest",
145
+ },
146
+ },
147
+ language="en",
148
+ output_format={},
149
+ duration=1.1,
150
+ )
151
+ for chunk in response:
152
+ yield chunk
153
+ ```
154
+
155
+ ## WebSocket
156
+
157
+ ```python
158
+ from cartesia import Cartesia
159
+ from cartesia.tts import TtsRequestEmbeddingSpecifierParams, OutputFormat_RawParams
160
+ import pyaudio
161
+
162
+ client = Cartesia(
163
+ api_key="YOUR_API_KEY",
164
+ )
165
+ voice_id = "a0e99841-438c-4a64-b679-ae501e7d6091"
166
+ voice = client.voices.get(id=voice_id)
167
+ transcript = "Hello! Welcome to Cartesia"
168
+
169
+ # You can check out our models at https://docs.cartesia.ai/getting-started/available-models
170
+ model_id = "sonic-english"
171
+
172
+ p = pyaudio.PyAudio()
173
+ rate = 22050
174
+
175
+ stream = None
176
+
177
+ # Set up the websocket connection
178
+ ws = client.tts.websocket()
179
+
180
+ # Generate and stream audio using the websocket
181
+ for output in ws.send(
182
+ model_id=model_id,
183
+ transcript=transcript,
184
+ voice={"embedding": voice.embedding},
185
+ stream=True,
186
+ output_format={
187
+ "container": "raw",
188
+ "encoding": "pcm_f32le",
189
+ "sample_rate": 22050
190
+ },
191
+ ):
192
+ buffer = output.audio
193
+
194
+ if not stream:
195
+ stream = p.open(format=pyaudio.paFloat32, channels=1, rate=rate, output=True)
196
+
197
+ # Write the audio data to the stream
198
+ stream.write(buffer)
199
+
200
+ stream.stop_stream()
201
+ stream.close()
202
+ p.terminate()
203
+
204
+ ws.close() # Close the websocket connection
205
+ ```
206
+
207
+ ## Advanced
208
+
209
+ ### Retries
210
+
211
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
212
+ as the request is deemed retriable and the number of retry attempts has not grown larger than the configured
213
+ retry limit (default: 2).
214
+
215
+ A request is deemed retriable when any of the following HTTP status codes is returned:
216
+
217
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
218
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
219
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
220
+
221
+ Use the `max_retries` request option to configure this behavior.
222
+
223
+ ```python
224
+ client.tts.bytes(..., request_options={
225
+ "max_retries": 1
226
+ })
227
+ ```
228
+
229
+ ### Timeouts
230
+
231
+ The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
232
+
233
+ ```python
234
+
235
+ from cartesia import Cartesia
236
+
237
+ client = Cartesia(
238
+ ...,
239
+ timeout=20.0,
240
+ )
241
+
242
+
243
+ # Override timeout for a specific method
244
+ client.tts.bytes(..., request_options={
245
+ "timeout_in_seconds": 1
246
+ })
247
+ ```
248
+
249
+ ### Custom Client
250
+
251
+ You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
252
+ and transports.
253
+ ```python
254
+ import httpx
255
+ from cartesia import Cartesia
256
+
257
+ client = Cartesia(
258
+ ...,
259
+ httpx_client=httpx.Client(
260
+ proxies="http://my.test.proxy.example.com",
261
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
262
+ ),
263
+ )
264
+ ```
265
+
266
+ ## Contributing
267
+
268
+ While we value open-source contributions to this SDK, this library is generated programmatically.
269
+ Additions made directly to this library would have to be moved over to our generation code,
270
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
271
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
272
+ an issue first to discuss with us!
273
+
274
+ On the other hand, contributions to the README are always very welcome!
@@ -0,0 +1,71 @@
1
+ [project]
2
+ name = "cartesia"
3
+
4
+ [tool.poetry]
5
+ name = "cartesia"
6
+ version = "2.0.0a2"
7
+ description = ""
8
+ readme = "README.md"
9
+ authors = []
10
+ keywords = []
11
+
12
+ classifiers = [
13
+ "Intended Audience :: Developers",
14
+ "Programming Language :: Python",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.8",
17
+ "Programming Language :: Python :: 3.9",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Operating System :: OS Independent",
22
+ "Operating System :: POSIX",
23
+ "Operating System :: MacOS",
24
+ "Operating System :: POSIX :: Linux",
25
+ "Operating System :: Microsoft :: Windows",
26
+ "Topic :: Software Development :: Libraries :: Python Modules",
27
+ "Typing :: Typed"
28
+ ]
29
+ packages = [
30
+ { include = "cartesia", from = "src"}
31
+ ]
32
+
33
+ [project.urls]
34
+ Repository = 'https://github.com/cartesia-ai/cartesia-python'
35
+
36
+ [tool.poetry.dependencies]
37
+ python = "^3.8"
38
+ aiohttp = ">=3.10.10"
39
+ audioop-lts = { version = "0.2.1", python = "^3.13"}
40
+ httpx = ">=0.21.2"
41
+ httpx-sse = "0.4.0"
42
+ iterators = ">=0.2.0"
43
+ pydantic = ">= 1.9.2"
44
+ pydantic-core = "^2.18.2"
45
+ pydub = ">=0.25.1"
46
+ typing_extensions = ">= 4.0.0"
47
+ websockets = ">=10.4"
48
+
49
+ [tool.poetry.dev-dependencies]
50
+ mypy = "1.0.1"
51
+ pytest = "^7.4.0"
52
+ pytest-asyncio = "^0.23.5"
53
+ python-dateutil = "^2.9.0"
54
+ types-python-dateutil = "^2.9.0.20240316"
55
+ numpy = ">=1.2.1"
56
+ ruff = "^0.5.6"
57
+
58
+ [tool.pytest.ini_options]
59
+ testpaths = [ "tests" ]
60
+ asyncio_mode = "auto"
61
+
62
+ [tool.mypy]
63
+ plugins = ["pydantic.mypy"]
64
+
65
+ [tool.ruff]
66
+ line-length = 120
67
+
68
+
69
+ [build-system]
70
+ requires = ["poetry-core"]
71
+ build-backend = "poetry.core.masonry.api"