cartesia 1.3.1__py3-none-any.whl → 2.0.0a0__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.
Files changed (174) hide show
  1. cartesia/__init__.py +288 -3
  2. cartesia/api_status/__init__.py +6 -0
  3. cartesia/api_status/client.py +104 -0
  4. cartesia/api_status/requests/__init__.py +5 -0
  5. cartesia/api_status/requests/api_info.py +8 -0
  6. cartesia/api_status/types/__init__.py +5 -0
  7. cartesia/api_status/types/api_info.py +20 -0
  8. cartesia/base_client.py +160 -0
  9. cartesia/client.py +163 -40
  10. cartesia/core/__init__.py +47 -0
  11. cartesia/core/api_error.py +15 -0
  12. cartesia/core/client_wrapper.py +55 -0
  13. cartesia/core/datetime_utils.py +28 -0
  14. cartesia/core/file.py +67 -0
  15. cartesia/core/http_client.py +499 -0
  16. cartesia/core/jsonable_encoder.py +101 -0
  17. cartesia/core/pydantic_utilities.py +296 -0
  18. cartesia/core/query_encoder.py +58 -0
  19. cartesia/core/remove_none_from_dict.py +11 -0
  20. cartesia/core/request_options.py +35 -0
  21. cartesia/core/serialization.py +272 -0
  22. cartesia/datasets/__init__.py +24 -0
  23. cartesia/datasets/client.py +422 -0
  24. cartesia/datasets/requests/__init__.py +15 -0
  25. cartesia/datasets/requests/create_dataset_request.py +7 -0
  26. cartesia/datasets/requests/dataset.py +9 -0
  27. cartesia/datasets/requests/dataset_file.py +9 -0
  28. cartesia/datasets/requests/paginated_dataset_files.py +10 -0
  29. cartesia/datasets/requests/paginated_datasets.py +10 -0
  30. cartesia/datasets/types/__init__.py +17 -0
  31. cartesia/datasets/types/create_dataset_request.py +19 -0
  32. cartesia/datasets/types/dataset.py +21 -0
  33. cartesia/datasets/types/dataset_file.py +21 -0
  34. cartesia/datasets/types/file_purpose.py +5 -0
  35. cartesia/datasets/types/paginated_dataset_files.py +21 -0
  36. cartesia/datasets/types/paginated_datasets.py +21 -0
  37. cartesia/embedding/__init__.py +5 -0
  38. cartesia/embedding/types/__init__.py +5 -0
  39. cartesia/embedding/types/embedding.py +201 -0
  40. cartesia/environment.py +7 -0
  41. cartesia/infill/__init__.py +2 -0
  42. cartesia/infill/client.py +294 -0
  43. cartesia/tts/__init__.py +167 -0
  44. cartesia/{_async_websocket.py → tts/_async_websocket.py} +159 -84
  45. cartesia/tts/_websocket.py +430 -0
  46. cartesia/tts/client.py +407 -0
  47. cartesia/tts/requests/__init__.py +76 -0
  48. cartesia/tts/requests/cancel_context_request.py +17 -0
  49. cartesia/tts/requests/controls.py +11 -0
  50. cartesia/tts/requests/generation_request.py +53 -0
  51. cartesia/tts/requests/mp_3_output_format.py +11 -0
  52. cartesia/tts/requests/output_format.py +30 -0
  53. cartesia/tts/requests/phoneme_timestamps.py +10 -0
  54. cartesia/tts/requests/raw_output_format.py +11 -0
  55. cartesia/tts/requests/speed.py +7 -0
  56. cartesia/tts/requests/tts_request.py +24 -0
  57. cartesia/tts/requests/tts_request_embedding_specifier.py +16 -0
  58. cartesia/tts/requests/tts_request_id_specifier.py +16 -0
  59. cartesia/tts/requests/tts_request_voice_specifier.py +7 -0
  60. cartesia/tts/requests/wav_output_format.py +7 -0
  61. cartesia/tts/requests/web_socket_base_response.py +11 -0
  62. cartesia/tts/requests/web_socket_chunk_response.py +8 -0
  63. cartesia/tts/requests/web_socket_done_response.py +7 -0
  64. cartesia/tts/requests/web_socket_error_response.py +7 -0
  65. cartesia/tts/requests/web_socket_flush_done_response.py +9 -0
  66. cartesia/tts/requests/web_socket_phoneme_timestamps_response.py +9 -0
  67. cartesia/tts/requests/web_socket_raw_output_format.py +11 -0
  68. cartesia/tts/requests/web_socket_request.py +7 -0
  69. cartesia/tts/requests/web_socket_response.py +69 -0
  70. cartesia/tts/requests/web_socket_stream_options.py +8 -0
  71. cartesia/tts/requests/web_socket_timestamps_response.py +9 -0
  72. cartesia/tts/requests/web_socket_tts_output.py +18 -0
  73. cartesia/tts/requests/web_socket_tts_request.py +24 -0
  74. cartesia/tts/requests/word_timestamps.py +10 -0
  75. cartesia/tts/socket_client.py +302 -0
  76. cartesia/tts/types/__init__.py +90 -0
  77. cartesia/tts/types/cancel_context_request.py +28 -0
  78. cartesia/tts/types/context_id.py +3 -0
  79. cartesia/tts/types/controls.py +22 -0
  80. cartesia/tts/types/emotion.py +29 -0
  81. cartesia/tts/types/flush_id.py +3 -0
  82. cartesia/tts/types/generation_request.py +66 -0
  83. cartesia/tts/types/mp_3_output_format.py +23 -0
  84. cartesia/tts/types/natural_specifier.py +5 -0
  85. cartesia/tts/types/numerical_specifier.py +3 -0
  86. cartesia/tts/types/output_format.py +58 -0
  87. cartesia/tts/types/phoneme_timestamps.py +21 -0
  88. cartesia/tts/types/raw_encoding.py +5 -0
  89. cartesia/tts/types/raw_output_format.py +22 -0
  90. cartesia/tts/types/speed.py +7 -0
  91. cartesia/tts/types/supported_language.py +7 -0
  92. cartesia/tts/types/tts_request.py +35 -0
  93. cartesia/tts/types/tts_request_embedding_specifier.py +27 -0
  94. cartesia/tts/types/tts_request_id_specifier.py +27 -0
  95. cartesia/tts/types/tts_request_voice_specifier.py +7 -0
  96. cartesia/tts/types/wav_output_format.py +17 -0
  97. cartesia/tts/types/web_socket_base_response.py +22 -0
  98. cartesia/tts/types/web_socket_chunk_response.py +20 -0
  99. cartesia/tts/types/web_socket_done_response.py +17 -0
  100. cartesia/tts/types/web_socket_error_response.py +19 -0
  101. cartesia/tts/types/web_socket_flush_done_response.py +21 -0
  102. cartesia/tts/types/web_socket_phoneme_timestamps_response.py +20 -0
  103. cartesia/tts/types/web_socket_raw_output_format.py +22 -0
  104. cartesia/tts/types/web_socket_request.py +7 -0
  105. cartesia/tts/types/web_socket_response.py +124 -0
  106. cartesia/tts/types/web_socket_stream_options.py +19 -0
  107. cartesia/tts/types/web_socket_timestamps_response.py +20 -0
  108. cartesia/tts/types/web_socket_tts_output.py +27 -0
  109. cartesia/tts/types/web_socket_tts_request.py +36 -0
  110. cartesia/tts/types/word_timestamps.py +21 -0
  111. cartesia/tts/utils/tts.py +64 -0
  112. cartesia/tts/utils/types.py +70 -0
  113. cartesia/version.py +3 -1
  114. cartesia/voice_changer/__init__.py +27 -0
  115. cartesia/voice_changer/client.py +395 -0
  116. cartesia/voice_changer/requests/__init__.py +15 -0
  117. cartesia/voice_changer/requests/streaming_response.py +36 -0
  118. cartesia/voice_changer/types/__init__.py +17 -0
  119. cartesia/voice_changer/types/output_format_container.py +5 -0
  120. cartesia/voice_changer/types/streaming_response.py +62 -0
  121. cartesia/voices/__init__.py +67 -0
  122. cartesia/voices/client.py +1812 -0
  123. cartesia/voices/requests/__init__.py +27 -0
  124. cartesia/voices/requests/create_voice_request.py +21 -0
  125. cartesia/voices/requests/embedding_response.py +8 -0
  126. cartesia/voices/requests/embedding_specifier.py +10 -0
  127. cartesia/voices/requests/id_specifier.py +10 -0
  128. cartesia/voices/requests/localize_dialect.py +6 -0
  129. cartesia/voices/requests/localize_voice_request.py +15 -0
  130. cartesia/voices/requests/mix_voice_specifier.py +7 -0
  131. cartesia/voices/requests/mix_voices_request.py +9 -0
  132. cartesia/voices/requests/update_voice_request.py +15 -0
  133. cartesia/voices/requests/voice.py +39 -0
  134. cartesia/voices/requests/voice_metadata.py +36 -0
  135. cartesia/voices/types/__init__.py +41 -0
  136. cartesia/voices/types/base_voice_id.py +5 -0
  137. cartesia/voices/types/clone_mode.py +5 -0
  138. cartesia/voices/types/create_voice_request.py +32 -0
  139. cartesia/voices/types/embedding_response.py +20 -0
  140. cartesia/voices/types/embedding_specifier.py +22 -0
  141. cartesia/voices/types/gender.py +5 -0
  142. cartesia/voices/types/id_specifier.py +22 -0
  143. cartesia/voices/types/localize_dialect.py +6 -0
  144. cartesia/voices/types/localize_english_dialect.py +5 -0
  145. cartesia/voices/types/localize_target_language.py +7 -0
  146. cartesia/voices/types/localize_voice_request.py +26 -0
  147. cartesia/voices/types/mix_voice_specifier.py +7 -0
  148. cartesia/voices/types/mix_voices_request.py +20 -0
  149. cartesia/voices/types/update_voice_request.py +27 -0
  150. cartesia/voices/types/voice.py +50 -0
  151. cartesia/voices/types/voice_id.py +3 -0
  152. cartesia/voices/types/voice_metadata.py +48 -0
  153. cartesia/voices/types/weight.py +3 -0
  154. cartesia-2.0.0a0.dist-info/METADATA +306 -0
  155. cartesia-2.0.0a0.dist-info/RECORD +158 -0
  156. {cartesia-1.3.1.dist-info → cartesia-2.0.0a0.dist-info}/WHEEL +1 -1
  157. cartesia/_async_sse.py +0 -95
  158. cartesia/_logger.py +0 -3
  159. cartesia/_sse.py +0 -143
  160. cartesia/_types.py +0 -70
  161. cartesia/_websocket.py +0 -358
  162. cartesia/async_client.py +0 -82
  163. cartesia/async_tts.py +0 -63
  164. cartesia/resource.py +0 -44
  165. cartesia/tts.py +0 -137
  166. cartesia/utils/deprecated.py +0 -55
  167. cartesia/utils/retry.py +0 -87
  168. cartesia/utils/tts.py +0 -78
  169. cartesia/voices.py +0 -208
  170. cartesia-1.3.1.dist-info/METADATA +0 -661
  171. cartesia-1.3.1.dist-info/RECORD +0 -23
  172. cartesia-1.3.1.dist-info/licenses/LICENSE.md +0 -21
  173. /cartesia/{utils/__init__.py → py.typed} +0 -0
  174. /cartesia/{_constants.py → tts/utils/constants.py} +0 -0
@@ -0,0 +1,1812 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+ from ..core.client_wrapper import SyncClientWrapper
5
+ from ..core.request_options import RequestOptions
6
+ from .types.voice import Voice
7
+ from ..core.pydantic_utilities import parse_obj_as
8
+ from json.decoder import JSONDecodeError
9
+ from ..core.api_error import ApiError
10
+ from ..embedding.types.embedding import Embedding
11
+ from ..tts.types.supported_language import SupportedLanguage
12
+ from .types.voice_id import VoiceId
13
+ from ..core.jsonable_encoder import jsonable_encoder
14
+ from .types.localize_target_language import LocalizeTargetLanguage
15
+ from .types.gender import Gender
16
+ from .requests.localize_dialect import LocalizeDialectParams
17
+ from .types.embedding_response import EmbeddingResponse
18
+ from ..core.serialization import convert_and_respect_annotation_metadata
19
+ from .requests.mix_voice_specifier import MixVoiceSpecifierParams
20
+ from .. import core
21
+ from .types.clone_mode import CloneMode
22
+ from .types.voice_metadata import VoiceMetadata
23
+ from ..core.client_wrapper import AsyncClientWrapper
24
+
25
+ # this is used as the default value for optional parameters
26
+ OMIT = typing.cast(typing.Any, ...)
27
+
28
+
29
+ class VoicesClient:
30
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
31
+ self._client_wrapper = client_wrapper
32
+
33
+ def list(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[Voice]:
34
+ """
35
+ Parameters
36
+ ----------
37
+ request_options : typing.Optional[RequestOptions]
38
+ Request-specific configuration.
39
+
40
+ Returns
41
+ -------
42
+ typing.List[Voice]
43
+
44
+ Examples
45
+ --------
46
+ from cartesia import Cartesia
47
+
48
+ client = Cartesia(
49
+ api_key="YOUR_API_KEY",
50
+ )
51
+ client.voices.list()
52
+ """
53
+ _response = self._client_wrapper.httpx_client.request(
54
+ "voices/",
55
+ method="GET",
56
+ request_options=request_options,
57
+ )
58
+ try:
59
+ if 200 <= _response.status_code < 300:
60
+ return typing.cast(
61
+ typing.List[Voice],
62
+ parse_obj_as(
63
+ type_=typing.List[Voice], # type: ignore
64
+ object_=_response.json(),
65
+ ),
66
+ )
67
+ _response_json = _response.json()
68
+ except JSONDecodeError:
69
+ raise ApiError(status_code=_response.status_code, body=_response.text)
70
+ raise ApiError(status_code=_response.status_code, body=_response_json)
71
+
72
+ def create(
73
+ self,
74
+ *,
75
+ name: str,
76
+ description: str,
77
+ embedding: Embedding,
78
+ language: typing.Optional[SupportedLanguage] = OMIT,
79
+ request_options: typing.Optional[RequestOptions] = None,
80
+ ) -> Voice:
81
+ """
82
+ Parameters
83
+ ----------
84
+ name : str
85
+ The name of the voice.
86
+
87
+ description : str
88
+ The description of the voice.
89
+
90
+ embedding : Embedding
91
+
92
+ language : typing.Optional[SupportedLanguage]
93
+
94
+ request_options : typing.Optional[RequestOptions]
95
+ Request-specific configuration.
96
+
97
+ Returns
98
+ -------
99
+ Voice
100
+
101
+ Examples
102
+ --------
103
+ from cartesia import Cartesia
104
+
105
+ client = Cartesia(
106
+ api_key="YOUR_API_KEY",
107
+ )
108
+ client.voices.create(
109
+ name="string",
110
+ description="string",
111
+ embedding=[
112
+ 1.0,
113
+ 1.0,
114
+ 1.0,
115
+ 1.0,
116
+ 1.0,
117
+ 1.0,
118
+ 1.0,
119
+ 1.0,
120
+ 1.0,
121
+ 1.0,
122
+ 1.0,
123
+ 1.0,
124
+ 1.0,
125
+ 1.0,
126
+ 1.0,
127
+ 1.0,
128
+ 1.0,
129
+ 1.0,
130
+ 1.0,
131
+ 1.0,
132
+ 1.0,
133
+ 1.0,
134
+ 1.0,
135
+ 1.0,
136
+ 1.0,
137
+ 1.0,
138
+ 1.0,
139
+ 1.0,
140
+ 1.0,
141
+ 1.0,
142
+ 1.0,
143
+ 1.0,
144
+ 1.0,
145
+ 1.0,
146
+ 1.0,
147
+ 1.0,
148
+ 1.0,
149
+ 1.0,
150
+ 1.0,
151
+ 1.0,
152
+ 1.0,
153
+ 1.0,
154
+ 1.0,
155
+ 1.0,
156
+ 1.0,
157
+ 1.0,
158
+ 1.0,
159
+ 1.0,
160
+ 1.0,
161
+ 1.0,
162
+ 1.0,
163
+ 1.0,
164
+ 1.0,
165
+ 1.0,
166
+ 1.0,
167
+ 1.0,
168
+ 1.0,
169
+ 1.0,
170
+ 1.0,
171
+ 1.0,
172
+ 1.0,
173
+ 1.0,
174
+ 1.0,
175
+ 1.0,
176
+ 1.0,
177
+ 1.0,
178
+ 1.0,
179
+ 1.0,
180
+ 1.0,
181
+ 1.0,
182
+ 1.0,
183
+ 1.0,
184
+ 1.0,
185
+ 1.0,
186
+ 1.0,
187
+ 1.0,
188
+ 1.0,
189
+ 1.0,
190
+ 1.0,
191
+ 1.0,
192
+ 1.0,
193
+ 1.0,
194
+ 1.0,
195
+ 1.0,
196
+ 1.0,
197
+ 1.0,
198
+ 1.0,
199
+ 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
302
+ 1.0,
303
+ 1.0,
304
+ ],
305
+ language="en",
306
+ )
307
+ """
308
+ _response = self._client_wrapper.httpx_client.request(
309
+ "voices/",
310
+ method="POST",
311
+ json={
312
+ "name": name,
313
+ "description": description,
314
+ "embedding": embedding,
315
+ "language": language,
316
+ },
317
+ request_options=request_options,
318
+ omit=OMIT,
319
+ )
320
+ try:
321
+ if 200 <= _response.status_code < 300:
322
+ return typing.cast(
323
+ Voice,
324
+ parse_obj_as(
325
+ type_=Voice, # type: ignore
326
+ object_=_response.json(),
327
+ ),
328
+ )
329
+ _response_json = _response.json()
330
+ except JSONDecodeError:
331
+ raise ApiError(status_code=_response.status_code, body=_response.text)
332
+ raise ApiError(status_code=_response.status_code, body=_response_json)
333
+
334
+ def delete(self, id: VoiceId, *, request_options: typing.Optional[RequestOptions] = None) -> None:
335
+ """
336
+ Parameters
337
+ ----------
338
+ id : VoiceId
339
+
340
+ request_options : typing.Optional[RequestOptions]
341
+ Request-specific configuration.
342
+
343
+ Returns
344
+ -------
345
+ None
346
+
347
+ Examples
348
+ --------
349
+ from cartesia import Cartesia
350
+
351
+ client = Cartesia(
352
+ api_key="YOUR_API_KEY",
353
+ )
354
+ client.voices.delete(
355
+ id="string",
356
+ )
357
+ """
358
+ _response = self._client_wrapper.httpx_client.request(
359
+ f"voices/{jsonable_encoder(id)}",
360
+ method="DELETE",
361
+ request_options=request_options,
362
+ )
363
+ try:
364
+ if 200 <= _response.status_code < 300:
365
+ return
366
+ _response_json = _response.json()
367
+ except JSONDecodeError:
368
+ raise ApiError(status_code=_response.status_code, body=_response.text)
369
+ raise ApiError(status_code=_response.status_code, body=_response_json)
370
+
371
+ def update(
372
+ self, id: VoiceId, *, name: str, description: str, request_options: typing.Optional[RequestOptions] = None
373
+ ) -> Voice:
374
+ """
375
+ Parameters
376
+ ----------
377
+ id : VoiceId
378
+
379
+ name : str
380
+ The name of the voice.
381
+
382
+ description : str
383
+ The description of the voice.
384
+
385
+ request_options : typing.Optional[RequestOptions]
386
+ Request-specific configuration.
387
+
388
+ Returns
389
+ -------
390
+ Voice
391
+
392
+ Examples
393
+ --------
394
+ from cartesia import Cartesia
395
+
396
+ client = Cartesia(
397
+ api_key="YOUR_API_KEY",
398
+ )
399
+ client.voices.update(
400
+ id="string",
401
+ name="string",
402
+ description="string",
403
+ )
404
+ """
405
+ _response = self._client_wrapper.httpx_client.request(
406
+ f"voices/{jsonable_encoder(id)}",
407
+ method="PATCH",
408
+ json={
409
+ "name": name,
410
+ "description": description,
411
+ },
412
+ request_options=request_options,
413
+ omit=OMIT,
414
+ )
415
+ try:
416
+ if 200 <= _response.status_code < 300:
417
+ return typing.cast(
418
+ Voice,
419
+ parse_obj_as(
420
+ type_=Voice, # type: ignore
421
+ object_=_response.json(),
422
+ ),
423
+ )
424
+ _response_json = _response.json()
425
+ except JSONDecodeError:
426
+ raise ApiError(status_code=_response.status_code, body=_response.text)
427
+ raise ApiError(status_code=_response.status_code, body=_response_json)
428
+
429
+ def get(self, id: VoiceId, *, request_options: typing.Optional[RequestOptions] = None) -> Voice:
430
+ """
431
+ Parameters
432
+ ----------
433
+ id : VoiceId
434
+
435
+ request_options : typing.Optional[RequestOptions]
436
+ Request-specific configuration.
437
+
438
+ Returns
439
+ -------
440
+ Voice
441
+
442
+ Examples
443
+ --------
444
+ from cartesia import Cartesia
445
+
446
+ client = Cartesia(
447
+ api_key="YOUR_API_KEY",
448
+ )
449
+ client.voices.get(
450
+ id="string",
451
+ )
452
+ """
453
+ _response = self._client_wrapper.httpx_client.request(
454
+ f"voices/{jsonable_encoder(id)}",
455
+ method="GET",
456
+ request_options=request_options,
457
+ )
458
+ try:
459
+ if 200 <= _response.status_code < 300:
460
+ return typing.cast(
461
+ Voice,
462
+ parse_obj_as(
463
+ type_=Voice, # type: ignore
464
+ object_=_response.json(),
465
+ ),
466
+ )
467
+ _response_json = _response.json()
468
+ except JSONDecodeError:
469
+ raise ApiError(status_code=_response.status_code, body=_response.text)
470
+ raise ApiError(status_code=_response.status_code, body=_response_json)
471
+
472
+ def localize(
473
+ self,
474
+ *,
475
+ embedding: Embedding,
476
+ language: LocalizeTargetLanguage,
477
+ original_speaker_gender: Gender,
478
+ dialect: typing.Optional[LocalizeDialectParams] = OMIT,
479
+ request_options: typing.Optional[RequestOptions] = None,
480
+ ) -> EmbeddingResponse:
481
+ """
482
+ Parameters
483
+ ----------
484
+ embedding : Embedding
485
+
486
+ language : LocalizeTargetLanguage
487
+
488
+ original_speaker_gender : Gender
489
+
490
+ dialect : typing.Optional[LocalizeDialectParams]
491
+
492
+ request_options : typing.Optional[RequestOptions]
493
+ Request-specific configuration.
494
+
495
+ Returns
496
+ -------
497
+ EmbeddingResponse
498
+
499
+ Examples
500
+ --------
501
+ from cartesia import Cartesia
502
+
503
+ client = Cartesia(
504
+ api_key="YOUR_API_KEY",
505
+ )
506
+ client.voices.localize(
507
+ embedding=[
508
+ 1.0,
509
+ 1.0,
510
+ 1.0,
511
+ 1.0,
512
+ 1.0,
513
+ 1.0,
514
+ 1.0,
515
+ 1.0,
516
+ 1.0,
517
+ 1.0,
518
+ 1.0,
519
+ 1.0,
520
+ 1.0,
521
+ 1.0,
522
+ 1.0,
523
+ 1.0,
524
+ 1.0,
525
+ 1.0,
526
+ 1.0,
527
+ 1.0,
528
+ 1.0,
529
+ 1.0,
530
+ 1.0,
531
+ 1.0,
532
+ 1.0,
533
+ 1.0,
534
+ 1.0,
535
+ 1.0,
536
+ 1.0,
537
+ 1.0,
538
+ 1.0,
539
+ 1.0,
540
+ 1.0,
541
+ 1.0,
542
+ 1.0,
543
+ 1.0,
544
+ 1.0,
545
+ 1.0,
546
+ 1.0,
547
+ 1.0,
548
+ 1.0,
549
+ 1.0,
550
+ 1.0,
551
+ 1.0,
552
+ 1.0,
553
+ 1.0,
554
+ 1.0,
555
+ 1.0,
556
+ 1.0,
557
+ 1.0,
558
+ 1.0,
559
+ 1.0,
560
+ 1.0,
561
+ 1.0,
562
+ 1.0,
563
+ 1.0,
564
+ 1.0,
565
+ 1.0,
566
+ 1.0,
567
+ 1.0,
568
+ 1.0,
569
+ 1.0,
570
+ 1.0,
571
+ 1.0,
572
+ 1.0,
573
+ 1.0,
574
+ 1.0,
575
+ 1.0,
576
+ 1.0,
577
+ 1.0,
578
+ 1.0,
579
+ 1.0,
580
+ 1.0,
581
+ 1.0,
582
+ 1.0,
583
+ 1.0,
584
+ 1.0,
585
+ 1.0,
586
+ 1.0,
587
+ 1.0,
588
+ 1.0,
589
+ 1.0,
590
+ 1.0,
591
+ 1.0,
592
+ 1.0,
593
+ 1.0,
594
+ 1.0,
595
+ 1.0,
596
+ 1.0,
597
+ 1.0,
598
+ 1.0,
599
+ 1.0,
600
+ 1.0,
601
+ 1.0,
602
+ 1.0,
603
+ 1.0,
604
+ 1.0,
605
+ 1.0,
606
+ 1.0,
607
+ 1.0,
608
+ 1.0,
609
+ 1.0,
610
+ 1.0,
611
+ 1.0,
612
+ 1.0,
613
+ 1.0,
614
+ 1.0,
615
+ 1.0,
616
+ 1.0,
617
+ 1.0,
618
+ 1.0,
619
+ 1.0,
620
+ 1.0,
621
+ 1.0,
622
+ 1.0,
623
+ 1.0,
624
+ 1.0,
625
+ 1.0,
626
+ 1.0,
627
+ 1.0,
628
+ 1.0,
629
+ 1.0,
630
+ 1.0,
631
+ 1.0,
632
+ 1.0,
633
+ 1.0,
634
+ 1.0,
635
+ 1.0,
636
+ 1.0,
637
+ 1.0,
638
+ 1.0,
639
+ 1.0,
640
+ 1.0,
641
+ 1.0,
642
+ 1.0,
643
+ 1.0,
644
+ 1.0,
645
+ 1.0,
646
+ 1.0,
647
+ 1.0,
648
+ 1.0,
649
+ 1.0,
650
+ 1.0,
651
+ 1.0,
652
+ 1.0,
653
+ 1.0,
654
+ 1.0,
655
+ 1.0,
656
+ 1.0,
657
+ 1.0,
658
+ 1.0,
659
+ 1.0,
660
+ 1.0,
661
+ 1.0,
662
+ 1.0,
663
+ 1.0,
664
+ 1.0,
665
+ 1.0,
666
+ 1.0,
667
+ 1.0,
668
+ 1.0,
669
+ 1.0,
670
+ 1.0,
671
+ 1.0,
672
+ 1.0,
673
+ 1.0,
674
+ 1.0,
675
+ 1.0,
676
+ 1.0,
677
+ 1.0,
678
+ 1.0,
679
+ 1.0,
680
+ 1.0,
681
+ 1.0,
682
+ 1.0,
683
+ 1.0,
684
+ 1.0,
685
+ 1.0,
686
+ 1.0,
687
+ 1.0,
688
+ 1.0,
689
+ 1.0,
690
+ 1.0,
691
+ 1.0,
692
+ 1.0,
693
+ 1.0,
694
+ 1.0,
695
+ 1.0,
696
+ 1.0,
697
+ 1.0,
698
+ 1.0,
699
+ 1.0,
700
+ ],
701
+ language="en",
702
+ original_speaker_gender="male",
703
+ dialect="au",
704
+ )
705
+ """
706
+ _response = self._client_wrapper.httpx_client.request(
707
+ "voices/localize",
708
+ method="POST",
709
+ json={
710
+ "embedding": embedding,
711
+ "language": language,
712
+ "original_speaker_gender": original_speaker_gender,
713
+ "dialect": convert_and_respect_annotation_metadata(
714
+ object_=dialect, annotation=LocalizeDialectParams, direction="write"
715
+ ),
716
+ },
717
+ request_options=request_options,
718
+ omit=OMIT,
719
+ )
720
+ try:
721
+ if 200 <= _response.status_code < 300:
722
+ return typing.cast(
723
+ EmbeddingResponse,
724
+ parse_obj_as(
725
+ type_=EmbeddingResponse, # type: ignore
726
+ object_=_response.json(),
727
+ ),
728
+ )
729
+ _response_json = _response.json()
730
+ except JSONDecodeError:
731
+ raise ApiError(status_code=_response.status_code, body=_response.text)
732
+ raise ApiError(status_code=_response.status_code, body=_response_json)
733
+
734
+ def mix(
735
+ self,
736
+ *,
737
+ voices: typing.Sequence[MixVoiceSpecifierParams],
738
+ request_options: typing.Optional[RequestOptions] = None,
739
+ ) -> EmbeddingResponse:
740
+ """
741
+ Parameters
742
+ ----------
743
+ voices : typing.Sequence[MixVoiceSpecifierParams]
744
+
745
+ request_options : typing.Optional[RequestOptions]
746
+ Request-specific configuration.
747
+
748
+ Returns
749
+ -------
750
+ EmbeddingResponse
751
+
752
+ Examples
753
+ --------
754
+ from cartesia import Cartesia
755
+
756
+ client = Cartesia(
757
+ api_key="YOUR_API_KEY",
758
+ )
759
+ client.voices.mix(
760
+ voices=[{"id": "string", "weight": 1.1}],
761
+ )
762
+ """
763
+ _response = self._client_wrapper.httpx_client.request(
764
+ "voices/mix",
765
+ method="POST",
766
+ json={
767
+ "voices": convert_and_respect_annotation_metadata(
768
+ object_=voices, annotation=typing.Sequence[MixVoiceSpecifierParams], direction="write"
769
+ ),
770
+ },
771
+ request_options=request_options,
772
+ omit=OMIT,
773
+ )
774
+ try:
775
+ if 200 <= _response.status_code < 300:
776
+ return typing.cast(
777
+ EmbeddingResponse,
778
+ parse_obj_as(
779
+ type_=EmbeddingResponse, # type: ignore
780
+ object_=_response.json(),
781
+ ),
782
+ )
783
+ _response_json = _response.json()
784
+ except JSONDecodeError:
785
+ raise ApiError(status_code=_response.status_code, body=_response.text)
786
+ raise ApiError(status_code=_response.status_code, body=_response_json)
787
+
788
+ def clone(
789
+ self,
790
+ *,
791
+ clip: core.File,
792
+ name: str,
793
+ language: SupportedLanguage,
794
+ mode: CloneMode,
795
+ enhance: bool,
796
+ description: typing.Optional[str] = OMIT,
797
+ transcript: typing.Optional[str] = OMIT,
798
+ request_options: typing.Optional[RequestOptions] = None,
799
+ ) -> VoiceMetadata:
800
+ """
801
+ Clone a voice from an audio clip. This endpoint has two modes, stability and similarity.
802
+
803
+ Similarity mode clones are more similar to the source clip, but may reproduce background noise. For these, use an audio clip about 5 seconds long.
804
+
805
+ Stability mode clones are more stable, but may not sound as similar to the source clip. For these, use an audio clip 10-20 seconds long.
806
+
807
+ Parameters
808
+ ----------
809
+ clip : core.File
810
+ See core.File for more documentation
811
+
812
+ name : str
813
+ The name of the voice.
814
+
815
+
816
+ language : SupportedLanguage
817
+ The language of the voice.
818
+
819
+
820
+ mode : CloneMode
821
+ Tradeoff between similarity and stability. Similarity clones sound more like the source clip, but may reproduce background noise. Stability clones always sound like a studio recording, but may not sound as similar to the source clip.
822
+
823
+
824
+ enhance : bool
825
+ Whether to enhance the clip to improve its quality before cloning. Useful if the clip has background noise.
826
+
827
+
828
+ description : typing.Optional[str]
829
+ A description for the voice.
830
+
831
+
832
+ transcript : typing.Optional[str]
833
+ Optional transcript of the words spoken in the audio clip. Only used for similarity mode.
834
+
835
+
836
+ request_options : typing.Optional[RequestOptions]
837
+ Request-specific configuration.
838
+
839
+ Returns
840
+ -------
841
+ VoiceMetadata
842
+
843
+ Examples
844
+ --------
845
+ from cartesia import Cartesia
846
+
847
+ client = Cartesia(
848
+ api_key="YOUR_API_KEY",
849
+ )
850
+ client.voices.clone(
851
+ name="A high-stability cloned voice",
852
+ description="Copied from Cartesia docs",
853
+ mode="stability",
854
+ language="en",
855
+ enhance=True,
856
+ )
857
+ """
858
+ _response = self._client_wrapper.httpx_client.request(
859
+ "voices/clone",
860
+ method="POST",
861
+ data={
862
+ "name": name,
863
+ "description": description,
864
+ "language": language,
865
+ "mode": mode,
866
+ "enhance": enhance,
867
+ "transcript": transcript,
868
+ },
869
+ files={
870
+ "clip": clip,
871
+ },
872
+ request_options=request_options,
873
+ omit=OMIT,
874
+ )
875
+ try:
876
+ if 200 <= _response.status_code < 300:
877
+ return typing.cast(
878
+ VoiceMetadata,
879
+ parse_obj_as(
880
+ type_=VoiceMetadata, # type: ignore
881
+ object_=_response.json(),
882
+ ),
883
+ )
884
+ _response_json = _response.json()
885
+ except JSONDecodeError:
886
+ raise ApiError(status_code=_response.status_code, body=_response.text)
887
+ raise ApiError(status_code=_response.status_code, body=_response_json)
888
+
889
+
890
+ class AsyncVoicesClient:
891
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
892
+ self._client_wrapper = client_wrapper
893
+
894
+ async def list(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[Voice]:
895
+ """
896
+ Parameters
897
+ ----------
898
+ request_options : typing.Optional[RequestOptions]
899
+ Request-specific configuration.
900
+
901
+ Returns
902
+ -------
903
+ typing.List[Voice]
904
+
905
+ Examples
906
+ --------
907
+ import asyncio
908
+
909
+ from cartesia import AsyncCartesia
910
+
911
+ client = AsyncCartesia(
912
+ api_key="YOUR_API_KEY",
913
+ )
914
+
915
+
916
+ async def main() -> None:
917
+ await client.voices.list()
918
+
919
+
920
+ asyncio.run(main())
921
+ """
922
+ _response = await self._client_wrapper.httpx_client.request(
923
+ "voices/",
924
+ method="GET",
925
+ request_options=request_options,
926
+ )
927
+ try:
928
+ if 200 <= _response.status_code < 300:
929
+ return typing.cast(
930
+ typing.List[Voice],
931
+ parse_obj_as(
932
+ type_=typing.List[Voice], # type: ignore
933
+ object_=_response.json(),
934
+ ),
935
+ )
936
+ _response_json = _response.json()
937
+ except JSONDecodeError:
938
+ raise ApiError(status_code=_response.status_code, body=_response.text)
939
+ raise ApiError(status_code=_response.status_code, body=_response_json)
940
+
941
+ async def create(
942
+ self,
943
+ *,
944
+ name: str,
945
+ description: str,
946
+ embedding: Embedding,
947
+ language: typing.Optional[SupportedLanguage] = OMIT,
948
+ request_options: typing.Optional[RequestOptions] = None,
949
+ ) -> Voice:
950
+ """
951
+ Parameters
952
+ ----------
953
+ name : str
954
+ The name of the voice.
955
+
956
+ description : str
957
+ The description of the voice.
958
+
959
+ embedding : Embedding
960
+
961
+ language : typing.Optional[SupportedLanguage]
962
+
963
+ request_options : typing.Optional[RequestOptions]
964
+ Request-specific configuration.
965
+
966
+ Returns
967
+ -------
968
+ Voice
969
+
970
+ Examples
971
+ --------
972
+ import asyncio
973
+
974
+ from cartesia import AsyncCartesia
975
+
976
+ client = AsyncCartesia(
977
+ api_key="YOUR_API_KEY",
978
+ )
979
+
980
+
981
+ async def main() -> None:
982
+ await client.voices.create(
983
+ name="string",
984
+ description="string",
985
+ embedding=[
986
+ 1.0,
987
+ 1.0,
988
+ 1.0,
989
+ 1.0,
990
+ 1.0,
991
+ 1.0,
992
+ 1.0,
993
+ 1.0,
994
+ 1.0,
995
+ 1.0,
996
+ 1.0,
997
+ 1.0,
998
+ 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0,
1092
+ 1.0,
1093
+ 1.0,
1094
+ 1.0,
1095
+ 1.0,
1096
+ 1.0,
1097
+ 1.0,
1098
+ 1.0,
1099
+ 1.0,
1100
+ 1.0,
1101
+ 1.0,
1102
+ 1.0,
1103
+ 1.0,
1104
+ 1.0,
1105
+ 1.0,
1106
+ 1.0,
1107
+ 1.0,
1108
+ 1.0,
1109
+ 1.0,
1110
+ 1.0,
1111
+ 1.0,
1112
+ 1.0,
1113
+ 1.0,
1114
+ 1.0,
1115
+ 1.0,
1116
+ 1.0,
1117
+ 1.0,
1118
+ 1.0,
1119
+ 1.0,
1120
+ 1.0,
1121
+ 1.0,
1122
+ 1.0,
1123
+ 1.0,
1124
+ 1.0,
1125
+ 1.0,
1126
+ 1.0,
1127
+ 1.0,
1128
+ 1.0,
1129
+ 1.0,
1130
+ 1.0,
1131
+ 1.0,
1132
+ 1.0,
1133
+ 1.0,
1134
+ 1.0,
1135
+ 1.0,
1136
+ 1.0,
1137
+ 1.0,
1138
+ 1.0,
1139
+ 1.0,
1140
+ 1.0,
1141
+ 1.0,
1142
+ 1.0,
1143
+ 1.0,
1144
+ 1.0,
1145
+ 1.0,
1146
+ 1.0,
1147
+ 1.0,
1148
+ 1.0,
1149
+ 1.0,
1150
+ 1.0,
1151
+ 1.0,
1152
+ 1.0,
1153
+ 1.0,
1154
+ 1.0,
1155
+ 1.0,
1156
+ 1.0,
1157
+ 1.0,
1158
+ 1.0,
1159
+ 1.0,
1160
+ 1.0,
1161
+ 1.0,
1162
+ 1.0,
1163
+ 1.0,
1164
+ 1.0,
1165
+ 1.0,
1166
+ 1.0,
1167
+ 1.0,
1168
+ 1.0,
1169
+ 1.0,
1170
+ 1.0,
1171
+ 1.0,
1172
+ 1.0,
1173
+ 1.0,
1174
+ 1.0,
1175
+ 1.0,
1176
+ 1.0,
1177
+ 1.0,
1178
+ ],
1179
+ language="en",
1180
+ )
1181
+
1182
+
1183
+ asyncio.run(main())
1184
+ """
1185
+ _response = await self._client_wrapper.httpx_client.request(
1186
+ "voices/",
1187
+ method="POST",
1188
+ json={
1189
+ "name": name,
1190
+ "description": description,
1191
+ "embedding": embedding,
1192
+ "language": language,
1193
+ },
1194
+ request_options=request_options,
1195
+ omit=OMIT,
1196
+ )
1197
+ try:
1198
+ if 200 <= _response.status_code < 300:
1199
+ return typing.cast(
1200
+ Voice,
1201
+ parse_obj_as(
1202
+ type_=Voice, # type: ignore
1203
+ object_=_response.json(),
1204
+ ),
1205
+ )
1206
+ _response_json = _response.json()
1207
+ except JSONDecodeError:
1208
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1209
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1210
+
1211
+ async def delete(self, id: VoiceId, *, request_options: typing.Optional[RequestOptions] = None) -> None:
1212
+ """
1213
+ Parameters
1214
+ ----------
1215
+ id : VoiceId
1216
+
1217
+ request_options : typing.Optional[RequestOptions]
1218
+ Request-specific configuration.
1219
+
1220
+ Returns
1221
+ -------
1222
+ None
1223
+
1224
+ Examples
1225
+ --------
1226
+ import asyncio
1227
+
1228
+ from cartesia import AsyncCartesia
1229
+
1230
+ client = AsyncCartesia(
1231
+ api_key="YOUR_API_KEY",
1232
+ )
1233
+
1234
+
1235
+ async def main() -> None:
1236
+ await client.voices.delete(
1237
+ id="string",
1238
+ )
1239
+
1240
+
1241
+ asyncio.run(main())
1242
+ """
1243
+ _response = await self._client_wrapper.httpx_client.request(
1244
+ f"voices/{jsonable_encoder(id)}",
1245
+ method="DELETE",
1246
+ request_options=request_options,
1247
+ )
1248
+ try:
1249
+ if 200 <= _response.status_code < 300:
1250
+ return
1251
+ _response_json = _response.json()
1252
+ except JSONDecodeError:
1253
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1254
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1255
+
1256
+ async def update(
1257
+ self, id: VoiceId, *, name: str, description: str, request_options: typing.Optional[RequestOptions] = None
1258
+ ) -> Voice:
1259
+ """
1260
+ Parameters
1261
+ ----------
1262
+ id : VoiceId
1263
+
1264
+ name : str
1265
+ The name of the voice.
1266
+
1267
+ description : str
1268
+ The description of the voice.
1269
+
1270
+ request_options : typing.Optional[RequestOptions]
1271
+ Request-specific configuration.
1272
+
1273
+ Returns
1274
+ -------
1275
+ Voice
1276
+
1277
+ Examples
1278
+ --------
1279
+ import asyncio
1280
+
1281
+ from cartesia import AsyncCartesia
1282
+
1283
+ client = AsyncCartesia(
1284
+ api_key="YOUR_API_KEY",
1285
+ )
1286
+
1287
+
1288
+ async def main() -> None:
1289
+ await client.voices.update(
1290
+ id="string",
1291
+ name="string",
1292
+ description="string",
1293
+ )
1294
+
1295
+
1296
+ asyncio.run(main())
1297
+ """
1298
+ _response = await self._client_wrapper.httpx_client.request(
1299
+ f"voices/{jsonable_encoder(id)}",
1300
+ method="PATCH",
1301
+ json={
1302
+ "name": name,
1303
+ "description": description,
1304
+ },
1305
+ request_options=request_options,
1306
+ omit=OMIT,
1307
+ )
1308
+ try:
1309
+ if 200 <= _response.status_code < 300:
1310
+ return typing.cast(
1311
+ Voice,
1312
+ parse_obj_as(
1313
+ type_=Voice, # type: ignore
1314
+ object_=_response.json(),
1315
+ ),
1316
+ )
1317
+ _response_json = _response.json()
1318
+ except JSONDecodeError:
1319
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1320
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1321
+
1322
+ async def get(self, id: VoiceId, *, request_options: typing.Optional[RequestOptions] = None) -> Voice:
1323
+ """
1324
+ Parameters
1325
+ ----------
1326
+ id : VoiceId
1327
+
1328
+ request_options : typing.Optional[RequestOptions]
1329
+ Request-specific configuration.
1330
+
1331
+ Returns
1332
+ -------
1333
+ Voice
1334
+
1335
+ Examples
1336
+ --------
1337
+ import asyncio
1338
+
1339
+ from cartesia import AsyncCartesia
1340
+
1341
+ client = AsyncCartesia(
1342
+ api_key="YOUR_API_KEY",
1343
+ )
1344
+
1345
+
1346
+ async def main() -> None:
1347
+ await client.voices.get(
1348
+ id="string",
1349
+ )
1350
+
1351
+
1352
+ asyncio.run(main())
1353
+ """
1354
+ _response = await self._client_wrapper.httpx_client.request(
1355
+ f"voices/{jsonable_encoder(id)}",
1356
+ method="GET",
1357
+ request_options=request_options,
1358
+ )
1359
+ try:
1360
+ if 200 <= _response.status_code < 300:
1361
+ return typing.cast(
1362
+ Voice,
1363
+ parse_obj_as(
1364
+ type_=Voice, # type: ignore
1365
+ object_=_response.json(),
1366
+ ),
1367
+ )
1368
+ _response_json = _response.json()
1369
+ except JSONDecodeError:
1370
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1371
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1372
+
1373
+ async def localize(
1374
+ self,
1375
+ *,
1376
+ embedding: Embedding,
1377
+ language: LocalizeTargetLanguage,
1378
+ original_speaker_gender: Gender,
1379
+ dialect: typing.Optional[LocalizeDialectParams] = OMIT,
1380
+ request_options: typing.Optional[RequestOptions] = None,
1381
+ ) -> EmbeddingResponse:
1382
+ """
1383
+ Parameters
1384
+ ----------
1385
+ embedding : Embedding
1386
+
1387
+ language : LocalizeTargetLanguage
1388
+
1389
+ original_speaker_gender : Gender
1390
+
1391
+ dialect : typing.Optional[LocalizeDialectParams]
1392
+
1393
+ request_options : typing.Optional[RequestOptions]
1394
+ Request-specific configuration.
1395
+
1396
+ Returns
1397
+ -------
1398
+ EmbeddingResponse
1399
+
1400
+ Examples
1401
+ --------
1402
+ import asyncio
1403
+
1404
+ from cartesia import AsyncCartesia
1405
+
1406
+ client = AsyncCartesia(
1407
+ api_key="YOUR_API_KEY",
1408
+ )
1409
+
1410
+
1411
+ async def main() -> None:
1412
+ await client.voices.localize(
1413
+ embedding=[
1414
+ 1.0,
1415
+ 1.0,
1416
+ 1.0,
1417
+ 1.0,
1418
+ 1.0,
1419
+ 1.0,
1420
+ 1.0,
1421
+ 1.0,
1422
+ 1.0,
1423
+ 1.0,
1424
+ 1.0,
1425
+ 1.0,
1426
+ 1.0,
1427
+ 1.0,
1428
+ 1.0,
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522
+ 1.0,
1523
+ 1.0,
1524
+ 1.0,
1525
+ 1.0,
1526
+ 1.0,
1527
+ 1.0,
1528
+ 1.0,
1529
+ 1.0,
1530
+ 1.0,
1531
+ 1.0,
1532
+ 1.0,
1533
+ 1.0,
1534
+ 1.0,
1535
+ 1.0,
1536
+ 1.0,
1537
+ 1.0,
1538
+ 1.0,
1539
+ 1.0,
1540
+ 1.0,
1541
+ 1.0,
1542
+ 1.0,
1543
+ 1.0,
1544
+ 1.0,
1545
+ 1.0,
1546
+ 1.0,
1547
+ 1.0,
1548
+ 1.0,
1549
+ 1.0,
1550
+ 1.0,
1551
+ 1.0,
1552
+ 1.0,
1553
+ 1.0,
1554
+ 1.0,
1555
+ 1.0,
1556
+ 1.0,
1557
+ 1.0,
1558
+ 1.0,
1559
+ 1.0,
1560
+ 1.0,
1561
+ 1.0,
1562
+ 1.0,
1563
+ 1.0,
1564
+ 1.0,
1565
+ 1.0,
1566
+ 1.0,
1567
+ 1.0,
1568
+ 1.0,
1569
+ 1.0,
1570
+ 1.0,
1571
+ 1.0,
1572
+ 1.0,
1573
+ 1.0,
1574
+ 1.0,
1575
+ 1.0,
1576
+ 1.0,
1577
+ 1.0,
1578
+ 1.0,
1579
+ 1.0,
1580
+ 1.0,
1581
+ 1.0,
1582
+ 1.0,
1583
+ 1.0,
1584
+ 1.0,
1585
+ 1.0,
1586
+ 1.0,
1587
+ 1.0,
1588
+ 1.0,
1589
+ 1.0,
1590
+ 1.0,
1591
+ 1.0,
1592
+ 1.0,
1593
+ 1.0,
1594
+ 1.0,
1595
+ 1.0,
1596
+ 1.0,
1597
+ 1.0,
1598
+ 1.0,
1599
+ 1.0,
1600
+ 1.0,
1601
+ 1.0,
1602
+ 1.0,
1603
+ 1.0,
1604
+ 1.0,
1605
+ 1.0,
1606
+ ],
1607
+ language="en",
1608
+ original_speaker_gender="male",
1609
+ dialect="au",
1610
+ )
1611
+
1612
+
1613
+ asyncio.run(main())
1614
+ """
1615
+ _response = await self._client_wrapper.httpx_client.request(
1616
+ "voices/localize",
1617
+ method="POST",
1618
+ json={
1619
+ "embedding": embedding,
1620
+ "language": language,
1621
+ "original_speaker_gender": original_speaker_gender,
1622
+ "dialect": convert_and_respect_annotation_metadata(
1623
+ object_=dialect, annotation=LocalizeDialectParams, direction="write"
1624
+ ),
1625
+ },
1626
+ request_options=request_options,
1627
+ omit=OMIT,
1628
+ )
1629
+ try:
1630
+ if 200 <= _response.status_code < 300:
1631
+ return typing.cast(
1632
+ EmbeddingResponse,
1633
+ parse_obj_as(
1634
+ type_=EmbeddingResponse, # type: ignore
1635
+ object_=_response.json(),
1636
+ ),
1637
+ )
1638
+ _response_json = _response.json()
1639
+ except JSONDecodeError:
1640
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1641
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1642
+
1643
+ async def mix(
1644
+ self,
1645
+ *,
1646
+ voices: typing.Sequence[MixVoiceSpecifierParams],
1647
+ request_options: typing.Optional[RequestOptions] = None,
1648
+ ) -> EmbeddingResponse:
1649
+ """
1650
+ Parameters
1651
+ ----------
1652
+ voices : typing.Sequence[MixVoiceSpecifierParams]
1653
+
1654
+ request_options : typing.Optional[RequestOptions]
1655
+ Request-specific configuration.
1656
+
1657
+ Returns
1658
+ -------
1659
+ EmbeddingResponse
1660
+
1661
+ Examples
1662
+ --------
1663
+ import asyncio
1664
+
1665
+ from cartesia import AsyncCartesia
1666
+
1667
+ client = AsyncCartesia(
1668
+ api_key="YOUR_API_KEY",
1669
+ )
1670
+
1671
+
1672
+ async def main() -> None:
1673
+ await client.voices.mix(
1674
+ voices=[{"id": "string", "weight": 1.1}],
1675
+ )
1676
+
1677
+
1678
+ asyncio.run(main())
1679
+ """
1680
+ _response = await self._client_wrapper.httpx_client.request(
1681
+ "voices/mix",
1682
+ method="POST",
1683
+ json={
1684
+ "voices": convert_and_respect_annotation_metadata(
1685
+ object_=voices, annotation=typing.Sequence[MixVoiceSpecifierParams], direction="write"
1686
+ ),
1687
+ },
1688
+ request_options=request_options,
1689
+ omit=OMIT,
1690
+ )
1691
+ try:
1692
+ if 200 <= _response.status_code < 300:
1693
+ return typing.cast(
1694
+ EmbeddingResponse,
1695
+ parse_obj_as(
1696
+ type_=EmbeddingResponse, # type: ignore
1697
+ object_=_response.json(),
1698
+ ),
1699
+ )
1700
+ _response_json = _response.json()
1701
+ except JSONDecodeError:
1702
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1703
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1704
+
1705
+ async def clone(
1706
+ self,
1707
+ *,
1708
+ clip: core.File,
1709
+ name: str,
1710
+ language: SupportedLanguage,
1711
+ mode: CloneMode,
1712
+ enhance: bool,
1713
+ description: typing.Optional[str] = OMIT,
1714
+ transcript: typing.Optional[str] = OMIT,
1715
+ request_options: typing.Optional[RequestOptions] = None,
1716
+ ) -> VoiceMetadata:
1717
+ """
1718
+ Clone a voice from an audio clip. This endpoint has two modes, stability and similarity.
1719
+
1720
+ Similarity mode clones are more similar to the source clip, but may reproduce background noise. For these, use an audio clip about 5 seconds long.
1721
+
1722
+ Stability mode clones are more stable, but may not sound as similar to the source clip. For these, use an audio clip 10-20 seconds long.
1723
+
1724
+ Parameters
1725
+ ----------
1726
+ clip : core.File
1727
+ See core.File for more documentation
1728
+
1729
+ name : str
1730
+ The name of the voice.
1731
+
1732
+
1733
+ language : SupportedLanguage
1734
+ The language of the voice.
1735
+
1736
+
1737
+ mode : CloneMode
1738
+ Tradeoff between similarity and stability. Similarity clones sound more like the source clip, but may reproduce background noise. Stability clones always sound like a studio recording, but may not sound as similar to the source clip.
1739
+
1740
+
1741
+ enhance : bool
1742
+ Whether to enhance the clip to improve its quality before cloning. Useful if the clip has background noise.
1743
+
1744
+
1745
+ description : typing.Optional[str]
1746
+ A description for the voice.
1747
+
1748
+
1749
+ transcript : typing.Optional[str]
1750
+ Optional transcript of the words spoken in the audio clip. Only used for similarity mode.
1751
+
1752
+
1753
+ request_options : typing.Optional[RequestOptions]
1754
+ Request-specific configuration.
1755
+
1756
+ Returns
1757
+ -------
1758
+ VoiceMetadata
1759
+
1760
+ Examples
1761
+ --------
1762
+ import asyncio
1763
+
1764
+ from cartesia import AsyncCartesia
1765
+
1766
+ client = AsyncCartesia(
1767
+ api_key="YOUR_API_KEY",
1768
+ )
1769
+
1770
+
1771
+ async def main() -> None:
1772
+ await client.voices.clone(
1773
+ name="A high-stability cloned voice",
1774
+ description="Copied from Cartesia docs",
1775
+ mode="stability",
1776
+ language="en",
1777
+ enhance=True,
1778
+ )
1779
+
1780
+
1781
+ asyncio.run(main())
1782
+ """
1783
+ _response = await self._client_wrapper.httpx_client.request(
1784
+ "voices/clone",
1785
+ method="POST",
1786
+ data={
1787
+ "name": name,
1788
+ "description": description,
1789
+ "language": language,
1790
+ "mode": mode,
1791
+ "enhance": enhance,
1792
+ "transcript": transcript,
1793
+ },
1794
+ files={
1795
+ "clip": clip,
1796
+ },
1797
+ request_options=request_options,
1798
+ omit=OMIT,
1799
+ )
1800
+ try:
1801
+ if 200 <= _response.status_code < 300:
1802
+ return typing.cast(
1803
+ VoiceMetadata,
1804
+ parse_obj_as(
1805
+ type_=VoiceMetadata, # type: ignore
1806
+ object_=_response.json(),
1807
+ ),
1808
+ )
1809
+ _response_json = _response.json()
1810
+ except JSONDecodeError:
1811
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1812
+ raise ApiError(status_code=_response.status_code, body=_response_json)