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