cartesia 1.4.0__py3-none-any.whl → 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cartesia/__init__.py +302 -3
- cartesia/api_status/__init__.py +6 -0
- cartesia/api_status/client.py +104 -0
- cartesia/api_status/requests/__init__.py +5 -0
- cartesia/api_status/requests/api_info.py +8 -0
- cartesia/api_status/types/__init__.py +5 -0
- cartesia/api_status/types/api_info.py +20 -0
- cartesia/base_client.py +156 -0
- cartesia/client.py +163 -40
- cartesia/core/__init__.py +50 -0
- cartesia/core/api_error.py +15 -0
- cartesia/core/client_wrapper.py +55 -0
- cartesia/core/datetime_utils.py +28 -0
- cartesia/core/file.py +67 -0
- cartesia/core/http_client.py +499 -0
- cartesia/core/jsonable_encoder.py +101 -0
- cartesia/core/pagination.py +88 -0
- cartesia/core/pydantic_utilities.py +296 -0
- cartesia/core/query_encoder.py +58 -0
- cartesia/core/remove_none_from_dict.py +11 -0
- cartesia/core/request_options.py +35 -0
- cartesia/core/serialization.py +272 -0
- cartesia/datasets/__init__.py +24 -0
- cartesia/datasets/requests/__init__.py +15 -0
- cartesia/datasets/requests/create_dataset_request.py +7 -0
- cartesia/datasets/requests/dataset.py +9 -0
- cartesia/datasets/requests/dataset_file.py +9 -0
- cartesia/datasets/requests/paginated_dataset_files.py +10 -0
- cartesia/datasets/requests/paginated_datasets.py +10 -0
- cartesia/datasets/types/__init__.py +17 -0
- cartesia/datasets/types/create_dataset_request.py +19 -0
- cartesia/datasets/types/dataset.py +21 -0
- cartesia/datasets/types/dataset_file.py +21 -0
- cartesia/datasets/types/file_purpose.py +5 -0
- cartesia/datasets/types/paginated_dataset_files.py +21 -0
- cartesia/datasets/types/paginated_datasets.py +21 -0
- cartesia/embedding/__init__.py +5 -0
- cartesia/embedding/types/__init__.py +5 -0
- cartesia/embedding/types/embedding.py +201 -0
- cartesia/environment.py +7 -0
- cartesia/infill/__init__.py +2 -0
- cartesia/infill/client.py +318 -0
- cartesia/tts/__init__.py +167 -0
- cartesia/{_async_websocket.py → tts/_async_websocket.py} +212 -85
- cartesia/tts/_websocket.py +479 -0
- cartesia/tts/client.py +407 -0
- cartesia/tts/requests/__init__.py +76 -0
- cartesia/tts/requests/cancel_context_request.py +17 -0
- cartesia/tts/requests/controls.py +11 -0
- cartesia/tts/requests/generation_request.py +58 -0
- cartesia/tts/requests/mp_3_output_format.py +11 -0
- cartesia/tts/requests/output_format.py +30 -0
- cartesia/tts/requests/phoneme_timestamps.py +10 -0
- cartesia/tts/requests/raw_output_format.py +11 -0
- cartesia/tts/requests/speed.py +7 -0
- cartesia/tts/requests/tts_request.py +24 -0
- cartesia/tts/requests/tts_request_embedding_specifier.py +16 -0
- cartesia/tts/requests/tts_request_id_specifier.py +16 -0
- cartesia/tts/requests/tts_request_voice_specifier.py +7 -0
- cartesia/tts/requests/wav_output_format.py +7 -0
- cartesia/tts/requests/web_socket_base_response.py +11 -0
- cartesia/tts/requests/web_socket_chunk_response.py +11 -0
- cartesia/tts/requests/web_socket_done_response.py +7 -0
- cartesia/tts/requests/web_socket_error_response.py +7 -0
- cartesia/tts/requests/web_socket_flush_done_response.py +9 -0
- cartesia/tts/requests/web_socket_phoneme_timestamps_response.py +9 -0
- cartesia/tts/requests/web_socket_raw_output_format.py +11 -0
- cartesia/tts/requests/web_socket_request.py +7 -0
- cartesia/tts/requests/web_socket_response.py +70 -0
- cartesia/tts/requests/web_socket_stream_options.py +8 -0
- cartesia/tts/requests/web_socket_timestamps_response.py +9 -0
- cartesia/tts/requests/web_socket_tts_output.py +18 -0
- cartesia/tts/requests/web_socket_tts_request.py +25 -0
- cartesia/tts/requests/word_timestamps.py +10 -0
- cartesia/tts/socket_client.py +302 -0
- cartesia/tts/types/__init__.py +90 -0
- cartesia/tts/types/cancel_context_request.py +28 -0
- cartesia/tts/types/context_id.py +3 -0
- cartesia/tts/types/controls.py +22 -0
- cartesia/tts/types/emotion.py +34 -0
- cartesia/tts/types/flush_id.py +3 -0
- cartesia/tts/types/generation_request.py +71 -0
- cartesia/tts/types/mp_3_output_format.py +23 -0
- cartesia/tts/types/natural_specifier.py +5 -0
- cartesia/tts/types/numerical_specifier.py +3 -0
- cartesia/tts/types/output_format.py +58 -0
- cartesia/tts/types/phoneme_timestamps.py +21 -0
- cartesia/tts/types/raw_encoding.py +5 -0
- cartesia/tts/types/raw_output_format.py +22 -0
- cartesia/tts/types/speed.py +7 -0
- cartesia/tts/types/supported_language.py +7 -0
- cartesia/tts/types/tts_request.py +35 -0
- cartesia/tts/types/tts_request_embedding_specifier.py +27 -0
- cartesia/tts/types/tts_request_id_specifier.py +27 -0
- cartesia/tts/types/tts_request_voice_specifier.py +7 -0
- cartesia/tts/types/wav_output_format.py +17 -0
- cartesia/tts/types/web_socket_base_response.py +22 -0
- cartesia/tts/types/web_socket_chunk_response.py +22 -0
- cartesia/tts/types/web_socket_done_response.py +17 -0
- cartesia/tts/types/web_socket_error_response.py +19 -0
- cartesia/tts/types/web_socket_flush_done_response.py +21 -0
- cartesia/tts/types/web_socket_phoneme_timestamps_response.py +20 -0
- cartesia/tts/types/web_socket_raw_output_format.py +22 -0
- cartesia/tts/types/web_socket_request.py +7 -0
- cartesia/tts/types/web_socket_response.py +125 -0
- cartesia/tts/types/web_socket_stream_options.py +19 -0
- cartesia/tts/types/web_socket_timestamps_response.py +20 -0
- cartesia/tts/types/web_socket_tts_output.py +29 -0
- cartesia/tts/types/web_socket_tts_request.py +37 -0
- cartesia/tts/types/word_timestamps.py +21 -0
- cartesia/{_constants.py → tts/utils/constants.py} +2 -2
- cartesia/tts/utils/tts.py +64 -0
- cartesia/tts/utils/types.py +70 -0
- cartesia/version.py +3 -1
- cartesia/voice_changer/__init__.py +27 -0
- cartesia/voice_changer/client.py +395 -0
- cartesia/voice_changer/requests/__init__.py +15 -0
- cartesia/voice_changer/requests/streaming_response.py +38 -0
- cartesia/voice_changer/types/__init__.py +17 -0
- cartesia/voice_changer/types/output_format_container.py +5 -0
- cartesia/voice_changer/types/streaming_response.py +64 -0
- cartesia/voices/__init__.py +81 -0
- cartesia/voices/client.py +1218 -0
- cartesia/voices/requests/__init__.py +29 -0
- cartesia/voices/requests/create_voice_request.py +23 -0
- cartesia/voices/requests/embedding_response.py +8 -0
- cartesia/voices/requests/embedding_specifier.py +10 -0
- cartesia/voices/requests/get_voices_response.py +24 -0
- cartesia/voices/requests/id_specifier.py +10 -0
- cartesia/voices/requests/localize_dialect.py +11 -0
- cartesia/voices/requests/localize_voice_request.py +28 -0
- cartesia/voices/requests/mix_voice_specifier.py +7 -0
- cartesia/voices/requests/mix_voices_request.py +9 -0
- cartesia/voices/requests/update_voice_request.py +15 -0
- cartesia/voices/requests/voice.py +43 -0
- cartesia/voices/requests/voice_metadata.py +36 -0
- cartesia/voices/types/__init__.py +53 -0
- cartesia/voices/types/base_voice_id.py +5 -0
- cartesia/voices/types/clone_mode.py +5 -0
- cartesia/voices/types/create_voice_request.py +34 -0
- cartesia/voices/types/embedding_response.py +20 -0
- cartesia/voices/types/embedding_specifier.py +22 -0
- cartesia/voices/types/gender.py +5 -0
- cartesia/voices/types/gender_presentation.py +5 -0
- cartesia/voices/types/get_voices_response.py +34 -0
- cartesia/voices/types/id_specifier.py +22 -0
- cartesia/voices/types/localize_dialect.py +11 -0
- cartesia/voices/types/localize_english_dialect.py +5 -0
- cartesia/voices/types/localize_french_dialect.py +5 -0
- cartesia/voices/types/localize_portuguese_dialect.py +5 -0
- cartesia/voices/types/localize_spanish_dialect.py +5 -0
- cartesia/voices/types/localize_target_language.py +7 -0
- cartesia/voices/types/localize_voice_request.py +39 -0
- cartesia/voices/types/mix_voice_specifier.py +7 -0
- cartesia/voices/types/mix_voices_request.py +20 -0
- cartesia/voices/types/update_voice_request.py +27 -0
- cartesia/voices/types/voice.py +54 -0
- cartesia/voices/types/voice_expand_options.py +5 -0
- cartesia/voices/types/voice_id.py +3 -0
- cartesia/voices/types/voice_metadata.py +48 -0
- cartesia/voices/types/weight.py +3 -0
- cartesia-2.0.0.dist-info/METADATA +414 -0
- cartesia-2.0.0.dist-info/RECORD +165 -0
- {cartesia-1.4.0.dist-info → cartesia-2.0.0.dist-info}/WHEEL +1 -1
- cartesia/_async_sse.py +0 -95
- cartesia/_logger.py +0 -3
- cartesia/_sse.py +0 -143
- cartesia/_types.py +0 -70
- cartesia/_websocket.py +0 -358
- cartesia/async_client.py +0 -82
- cartesia/async_tts.py +0 -176
- cartesia/resource.py +0 -44
- cartesia/tts.py +0 -292
- cartesia/utils/deprecated.py +0 -55
- cartesia/utils/retry.py +0 -87
- cartesia/utils/tts.py +0 -78
- cartesia/voices.py +0 -204
- cartesia-1.4.0.dist-info/METADATA +0 -663
- cartesia-1.4.0.dist-info/RECORD +0 -23
- cartesia-1.4.0.dist-info/licenses/LICENSE.md +0 -21
- /cartesia/{utils/__init__.py → py.typed} +0 -0
@@ -0,0 +1,395 @@
|
|
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 .. import core
|
6
|
+
from .types.output_format_container import OutputFormatContainer
|
7
|
+
from ..tts.types.raw_encoding import RawEncoding
|
8
|
+
from ..core.request_options import RequestOptions
|
9
|
+
from json.decoder import JSONDecodeError
|
10
|
+
from ..core.api_error import ApiError
|
11
|
+
from .types.streaming_response import StreamingResponse
|
12
|
+
from ..core.pydantic_utilities import parse_obj_as
|
13
|
+
import json
|
14
|
+
from ..core.client_wrapper import AsyncClientWrapper
|
15
|
+
|
16
|
+
# this is used as the default value for optional parameters
|
17
|
+
OMIT = typing.cast(typing.Any, ...)
|
18
|
+
|
19
|
+
|
20
|
+
class VoiceChangerClient:
|
21
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
22
|
+
self._client_wrapper = client_wrapper
|
23
|
+
|
24
|
+
def bytes(
|
25
|
+
self,
|
26
|
+
*,
|
27
|
+
clip: core.File,
|
28
|
+
voice_id: str,
|
29
|
+
output_format_container: OutputFormatContainer,
|
30
|
+
output_format_sample_rate: int,
|
31
|
+
output_format_encoding: typing.Optional[RawEncoding] = OMIT,
|
32
|
+
output_format_bit_rate: typing.Optional[int] = OMIT,
|
33
|
+
request_options: typing.Optional[RequestOptions] = None,
|
34
|
+
) -> typing.Iterator[bytes]:
|
35
|
+
"""
|
36
|
+
Takes an audio file of speech, and returns an audio file of speech spoken with the same intonation, but with a different voice.
|
37
|
+
|
38
|
+
This endpoint is priced at 15 characters per second of input audio.
|
39
|
+
|
40
|
+
Parameters
|
41
|
+
----------
|
42
|
+
clip : core.File
|
43
|
+
See core.File for more documentation
|
44
|
+
|
45
|
+
voice_id : str
|
46
|
+
|
47
|
+
output_format_container : OutputFormatContainer
|
48
|
+
|
49
|
+
output_format_sample_rate : int
|
50
|
+
|
51
|
+
output_format_encoding : typing.Optional[RawEncoding]
|
52
|
+
Required for `raw` and `wav` containers.
|
53
|
+
|
54
|
+
|
55
|
+
output_format_bit_rate : typing.Optional[int]
|
56
|
+
Required for `mp3` containers.
|
57
|
+
|
58
|
+
|
59
|
+
request_options : typing.Optional[RequestOptions]
|
60
|
+
Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.
|
61
|
+
|
62
|
+
Yields
|
63
|
+
------
|
64
|
+
typing.Iterator[bytes]
|
65
|
+
|
66
|
+
Examples
|
67
|
+
--------
|
68
|
+
from cartesia import Cartesia
|
69
|
+
|
70
|
+
client = Cartesia(
|
71
|
+
api_key="YOUR_API_KEY",
|
72
|
+
)
|
73
|
+
client.voice_changer.bytes(
|
74
|
+
voice_id="694f9389-aac1-45b6-b726-9d9369183238",
|
75
|
+
output_format_container="mp3",
|
76
|
+
output_format_sample_rate=44100,
|
77
|
+
output_format_bit_rate=128000,
|
78
|
+
)
|
79
|
+
"""
|
80
|
+
with self._client_wrapper.httpx_client.stream(
|
81
|
+
"voice-changer/bytes",
|
82
|
+
method="POST",
|
83
|
+
data={
|
84
|
+
"voice[id]": voice_id,
|
85
|
+
"output_format[container]": output_format_container,
|
86
|
+
"output_format[sample_rate]": output_format_sample_rate,
|
87
|
+
"output_format[encoding]": output_format_encoding,
|
88
|
+
"output_format[bit_rate]": output_format_bit_rate,
|
89
|
+
},
|
90
|
+
files={
|
91
|
+
"clip": clip,
|
92
|
+
},
|
93
|
+
request_options=request_options,
|
94
|
+
omit=OMIT,
|
95
|
+
) as _response:
|
96
|
+
try:
|
97
|
+
if 200 <= _response.status_code < 300:
|
98
|
+
_chunk_size = request_options.get("chunk_size", None) if request_options is not None else None
|
99
|
+
for _chunk in _response.iter_bytes(chunk_size=_chunk_size):
|
100
|
+
yield _chunk
|
101
|
+
return
|
102
|
+
_response.read()
|
103
|
+
_response_json = _response.json()
|
104
|
+
except JSONDecodeError:
|
105
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
106
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
107
|
+
|
108
|
+
def sse(
|
109
|
+
self,
|
110
|
+
*,
|
111
|
+
clip: core.File,
|
112
|
+
voice_id: str,
|
113
|
+
output_format_container: OutputFormatContainer,
|
114
|
+
output_format_sample_rate: int,
|
115
|
+
output_format_encoding: typing.Optional[RawEncoding] = OMIT,
|
116
|
+
output_format_bit_rate: typing.Optional[int] = OMIT,
|
117
|
+
request_options: typing.Optional[RequestOptions] = None,
|
118
|
+
) -> typing.Iterator[StreamingResponse]:
|
119
|
+
"""
|
120
|
+
Parameters
|
121
|
+
----------
|
122
|
+
clip : core.File
|
123
|
+
See core.File for more documentation
|
124
|
+
|
125
|
+
voice_id : str
|
126
|
+
|
127
|
+
output_format_container : OutputFormatContainer
|
128
|
+
|
129
|
+
output_format_sample_rate : int
|
130
|
+
|
131
|
+
output_format_encoding : typing.Optional[RawEncoding]
|
132
|
+
Required for `raw` and `wav` containers.
|
133
|
+
|
134
|
+
|
135
|
+
output_format_bit_rate : typing.Optional[int]
|
136
|
+
Required for `mp3` containers.
|
137
|
+
|
138
|
+
|
139
|
+
request_options : typing.Optional[RequestOptions]
|
140
|
+
Request-specific configuration.
|
141
|
+
|
142
|
+
Yields
|
143
|
+
------
|
144
|
+
typing.Iterator[StreamingResponse]
|
145
|
+
|
146
|
+
Examples
|
147
|
+
--------
|
148
|
+
from cartesia import Cartesia
|
149
|
+
|
150
|
+
client = Cartesia(
|
151
|
+
api_key="YOUR_API_KEY",
|
152
|
+
)
|
153
|
+
response = client.voice_changer.sse(
|
154
|
+
voice_id="694f9389-aac1-45b6-b726-9d9369183238",
|
155
|
+
output_format_container="mp3",
|
156
|
+
output_format_sample_rate=44100,
|
157
|
+
output_format_bit_rate=128000,
|
158
|
+
)
|
159
|
+
for chunk in response:
|
160
|
+
yield chunk
|
161
|
+
"""
|
162
|
+
with self._client_wrapper.httpx_client.stream(
|
163
|
+
"voice-changer/sse",
|
164
|
+
method="POST",
|
165
|
+
data={
|
166
|
+
"voice[id]": voice_id,
|
167
|
+
"output_format[container]": output_format_container,
|
168
|
+
"output_format[sample_rate]": output_format_sample_rate,
|
169
|
+
"output_format[encoding]": output_format_encoding,
|
170
|
+
"output_format[bit_rate]": output_format_bit_rate,
|
171
|
+
},
|
172
|
+
files={
|
173
|
+
"clip": clip,
|
174
|
+
},
|
175
|
+
request_options=request_options,
|
176
|
+
omit=OMIT,
|
177
|
+
) as _response:
|
178
|
+
try:
|
179
|
+
if 200 <= _response.status_code < 300:
|
180
|
+
for _text in _response.iter_lines():
|
181
|
+
try:
|
182
|
+
if len(_text) == 0:
|
183
|
+
continue
|
184
|
+
yield typing.cast(
|
185
|
+
StreamingResponse,
|
186
|
+
parse_obj_as(
|
187
|
+
type_=StreamingResponse, # type: ignore
|
188
|
+
object_=json.loads(_text),
|
189
|
+
),
|
190
|
+
)
|
191
|
+
except:
|
192
|
+
pass
|
193
|
+
return
|
194
|
+
_response.read()
|
195
|
+
_response_json = _response.json()
|
196
|
+
except JSONDecodeError:
|
197
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
198
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
199
|
+
|
200
|
+
|
201
|
+
class AsyncVoiceChangerClient:
|
202
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
203
|
+
self._client_wrapper = client_wrapper
|
204
|
+
|
205
|
+
async def bytes(
|
206
|
+
self,
|
207
|
+
*,
|
208
|
+
clip: core.File,
|
209
|
+
voice_id: str,
|
210
|
+
output_format_container: OutputFormatContainer,
|
211
|
+
output_format_sample_rate: int,
|
212
|
+
output_format_encoding: typing.Optional[RawEncoding] = OMIT,
|
213
|
+
output_format_bit_rate: typing.Optional[int] = OMIT,
|
214
|
+
request_options: typing.Optional[RequestOptions] = None,
|
215
|
+
) -> typing.AsyncIterator[bytes]:
|
216
|
+
"""
|
217
|
+
Takes an audio file of speech, and returns an audio file of speech spoken with the same intonation, but with a different voice.
|
218
|
+
|
219
|
+
This endpoint is priced at 15 characters per second of input audio.
|
220
|
+
|
221
|
+
Parameters
|
222
|
+
----------
|
223
|
+
clip : core.File
|
224
|
+
See core.File for more documentation
|
225
|
+
|
226
|
+
voice_id : str
|
227
|
+
|
228
|
+
output_format_container : OutputFormatContainer
|
229
|
+
|
230
|
+
output_format_sample_rate : int
|
231
|
+
|
232
|
+
output_format_encoding : typing.Optional[RawEncoding]
|
233
|
+
Required for `raw` and `wav` containers.
|
234
|
+
|
235
|
+
|
236
|
+
output_format_bit_rate : typing.Optional[int]
|
237
|
+
Required for `mp3` containers.
|
238
|
+
|
239
|
+
|
240
|
+
request_options : typing.Optional[RequestOptions]
|
241
|
+
Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.
|
242
|
+
|
243
|
+
Yields
|
244
|
+
------
|
245
|
+
typing.AsyncIterator[bytes]
|
246
|
+
|
247
|
+
Examples
|
248
|
+
--------
|
249
|
+
import asyncio
|
250
|
+
|
251
|
+
from cartesia import AsyncCartesia
|
252
|
+
|
253
|
+
client = AsyncCartesia(
|
254
|
+
api_key="YOUR_API_KEY",
|
255
|
+
)
|
256
|
+
|
257
|
+
|
258
|
+
async def main() -> None:
|
259
|
+
await client.voice_changer.bytes(
|
260
|
+
voice_id="694f9389-aac1-45b6-b726-9d9369183238",
|
261
|
+
output_format_container="mp3",
|
262
|
+
output_format_sample_rate=44100,
|
263
|
+
output_format_bit_rate=128000,
|
264
|
+
)
|
265
|
+
|
266
|
+
|
267
|
+
asyncio.run(main())
|
268
|
+
"""
|
269
|
+
async with self._client_wrapper.httpx_client.stream(
|
270
|
+
"voice-changer/bytes",
|
271
|
+
method="POST",
|
272
|
+
data={
|
273
|
+
"voice[id]": voice_id,
|
274
|
+
"output_format[container]": output_format_container,
|
275
|
+
"output_format[sample_rate]": output_format_sample_rate,
|
276
|
+
"output_format[encoding]": output_format_encoding,
|
277
|
+
"output_format[bit_rate]": output_format_bit_rate,
|
278
|
+
},
|
279
|
+
files={
|
280
|
+
"clip": clip,
|
281
|
+
},
|
282
|
+
request_options=request_options,
|
283
|
+
omit=OMIT,
|
284
|
+
) as _response:
|
285
|
+
try:
|
286
|
+
if 200 <= _response.status_code < 300:
|
287
|
+
_chunk_size = request_options.get("chunk_size", None) if request_options is not None else None
|
288
|
+
async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size):
|
289
|
+
yield _chunk
|
290
|
+
return
|
291
|
+
await _response.aread()
|
292
|
+
_response_json = _response.json()
|
293
|
+
except JSONDecodeError:
|
294
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
295
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
296
|
+
|
297
|
+
async def sse(
|
298
|
+
self,
|
299
|
+
*,
|
300
|
+
clip: core.File,
|
301
|
+
voice_id: str,
|
302
|
+
output_format_container: OutputFormatContainer,
|
303
|
+
output_format_sample_rate: int,
|
304
|
+
output_format_encoding: typing.Optional[RawEncoding] = OMIT,
|
305
|
+
output_format_bit_rate: typing.Optional[int] = OMIT,
|
306
|
+
request_options: typing.Optional[RequestOptions] = None,
|
307
|
+
) -> typing.AsyncIterator[StreamingResponse]:
|
308
|
+
"""
|
309
|
+
Parameters
|
310
|
+
----------
|
311
|
+
clip : core.File
|
312
|
+
See core.File for more documentation
|
313
|
+
|
314
|
+
voice_id : str
|
315
|
+
|
316
|
+
output_format_container : OutputFormatContainer
|
317
|
+
|
318
|
+
output_format_sample_rate : int
|
319
|
+
|
320
|
+
output_format_encoding : typing.Optional[RawEncoding]
|
321
|
+
Required for `raw` and `wav` containers.
|
322
|
+
|
323
|
+
|
324
|
+
output_format_bit_rate : typing.Optional[int]
|
325
|
+
Required for `mp3` containers.
|
326
|
+
|
327
|
+
|
328
|
+
request_options : typing.Optional[RequestOptions]
|
329
|
+
Request-specific configuration.
|
330
|
+
|
331
|
+
Yields
|
332
|
+
------
|
333
|
+
typing.AsyncIterator[StreamingResponse]
|
334
|
+
|
335
|
+
Examples
|
336
|
+
--------
|
337
|
+
import asyncio
|
338
|
+
|
339
|
+
from cartesia import AsyncCartesia
|
340
|
+
|
341
|
+
client = AsyncCartesia(
|
342
|
+
api_key="YOUR_API_KEY",
|
343
|
+
)
|
344
|
+
|
345
|
+
|
346
|
+
async def main() -> None:
|
347
|
+
response = await client.voice_changer.sse(
|
348
|
+
voice_id="694f9389-aac1-45b6-b726-9d9369183238",
|
349
|
+
output_format_container="mp3",
|
350
|
+
output_format_sample_rate=44100,
|
351
|
+
output_format_bit_rate=128000,
|
352
|
+
)
|
353
|
+
async for chunk in response:
|
354
|
+
yield chunk
|
355
|
+
|
356
|
+
|
357
|
+
asyncio.run(main())
|
358
|
+
"""
|
359
|
+
async with self._client_wrapper.httpx_client.stream(
|
360
|
+
"voice-changer/sse",
|
361
|
+
method="POST",
|
362
|
+
data={
|
363
|
+
"voice[id]": voice_id,
|
364
|
+
"output_format[container]": output_format_container,
|
365
|
+
"output_format[sample_rate]": output_format_sample_rate,
|
366
|
+
"output_format[encoding]": output_format_encoding,
|
367
|
+
"output_format[bit_rate]": output_format_bit_rate,
|
368
|
+
},
|
369
|
+
files={
|
370
|
+
"clip": clip,
|
371
|
+
},
|
372
|
+
request_options=request_options,
|
373
|
+
omit=OMIT,
|
374
|
+
) as _response:
|
375
|
+
try:
|
376
|
+
if 200 <= _response.status_code < 300:
|
377
|
+
async for _text in _response.aiter_lines():
|
378
|
+
try:
|
379
|
+
if len(_text) == 0:
|
380
|
+
continue
|
381
|
+
yield typing.cast(
|
382
|
+
StreamingResponse,
|
383
|
+
parse_obj_as(
|
384
|
+
type_=StreamingResponse, # type: ignore
|
385
|
+
object_=json.loads(_text),
|
386
|
+
),
|
387
|
+
)
|
388
|
+
except:
|
389
|
+
pass
|
390
|
+
return
|
391
|
+
await _response.aread()
|
392
|
+
_response_json = _response.json()
|
393
|
+
except JSONDecodeError:
|
394
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
395
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
from .streaming_response import (
|
4
|
+
StreamingResponseParams,
|
5
|
+
StreamingResponse_ChunkParams,
|
6
|
+
StreamingResponse_DoneParams,
|
7
|
+
StreamingResponse_ErrorParams,
|
8
|
+
)
|
9
|
+
|
10
|
+
__all__ = [
|
11
|
+
"StreamingResponseParams",
|
12
|
+
"StreamingResponse_ChunkParams",
|
13
|
+
"StreamingResponse_DoneParams",
|
14
|
+
"StreamingResponse_ErrorParams",
|
15
|
+
]
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
import typing_extensions
|
5
|
+
import typing
|
6
|
+
import typing_extensions
|
7
|
+
from ...tts.types.flush_id import FlushId
|
8
|
+
from ...tts.types.context_id import ContextId
|
9
|
+
|
10
|
+
|
11
|
+
class StreamingResponse_ChunkParams(typing_extensions.TypedDict):
|
12
|
+
type: typing.Literal["chunk"]
|
13
|
+
data: str
|
14
|
+
step_time: float
|
15
|
+
flush_id: typing_extensions.NotRequired[FlushId]
|
16
|
+
context_id: typing_extensions.NotRequired[ContextId]
|
17
|
+
status_code: int
|
18
|
+
done: bool
|
19
|
+
|
20
|
+
|
21
|
+
class StreamingResponse_DoneParams(typing_extensions.TypedDict):
|
22
|
+
type: typing.Literal["done"]
|
23
|
+
context_id: typing_extensions.NotRequired[ContextId]
|
24
|
+
status_code: int
|
25
|
+
done: bool
|
26
|
+
|
27
|
+
|
28
|
+
class StreamingResponse_ErrorParams(typing_extensions.TypedDict):
|
29
|
+
type: typing.Literal["error"]
|
30
|
+
error: str
|
31
|
+
context_id: typing_extensions.NotRequired[ContextId]
|
32
|
+
status_code: int
|
33
|
+
done: bool
|
34
|
+
|
35
|
+
|
36
|
+
StreamingResponseParams = typing.Union[
|
37
|
+
StreamingResponse_ChunkParams, StreamingResponse_DoneParams, StreamingResponse_ErrorParams
|
38
|
+
]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
from .output_format_container import OutputFormatContainer
|
4
|
+
from .streaming_response import (
|
5
|
+
StreamingResponse,
|
6
|
+
StreamingResponse_Chunk,
|
7
|
+
StreamingResponse_Done,
|
8
|
+
StreamingResponse_Error,
|
9
|
+
)
|
10
|
+
|
11
|
+
__all__ = [
|
12
|
+
"OutputFormatContainer",
|
13
|
+
"StreamingResponse",
|
14
|
+
"StreamingResponse_Chunk",
|
15
|
+
"StreamingResponse_Done",
|
16
|
+
"StreamingResponse_Error",
|
17
|
+
]
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
from ...core.pydantic_utilities import UniversalBaseModel
|
5
|
+
import typing
|
6
|
+
from ...tts.types.flush_id import FlushId
|
7
|
+
from ...tts.types.context_id import ContextId
|
8
|
+
from ...core.pydantic_utilities import IS_PYDANTIC_V2
|
9
|
+
import pydantic
|
10
|
+
|
11
|
+
|
12
|
+
class StreamingResponse_Chunk(UniversalBaseModel):
|
13
|
+
type: typing.Literal["chunk"] = "chunk"
|
14
|
+
data: str
|
15
|
+
step_time: float
|
16
|
+
flush_id: typing.Optional[FlushId] = None
|
17
|
+
context_id: typing.Optional[ContextId] = None
|
18
|
+
status_code: int
|
19
|
+
done: bool
|
20
|
+
|
21
|
+
if IS_PYDANTIC_V2:
|
22
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
|
23
|
+
else:
|
24
|
+
|
25
|
+
class Config:
|
26
|
+
frozen = True
|
27
|
+
smart_union = True
|
28
|
+
extra = pydantic.Extra.allow
|
29
|
+
|
30
|
+
|
31
|
+
class StreamingResponse_Done(UniversalBaseModel):
|
32
|
+
type: typing.Literal["done"] = "done"
|
33
|
+
context_id: typing.Optional[ContextId] = None
|
34
|
+
status_code: int
|
35
|
+
done: bool
|
36
|
+
|
37
|
+
if IS_PYDANTIC_V2:
|
38
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
|
39
|
+
else:
|
40
|
+
|
41
|
+
class Config:
|
42
|
+
frozen = True
|
43
|
+
smart_union = True
|
44
|
+
extra = pydantic.Extra.allow
|
45
|
+
|
46
|
+
|
47
|
+
class StreamingResponse_Error(UniversalBaseModel):
|
48
|
+
type: typing.Literal["error"] = "error"
|
49
|
+
error: str
|
50
|
+
context_id: typing.Optional[ContextId] = None
|
51
|
+
status_code: int
|
52
|
+
done: bool
|
53
|
+
|
54
|
+
if IS_PYDANTIC_V2:
|
55
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
|
56
|
+
else:
|
57
|
+
|
58
|
+
class Config:
|
59
|
+
frozen = True
|
60
|
+
smart_union = True
|
61
|
+
extra = pydantic.Extra.allow
|
62
|
+
|
63
|
+
|
64
|
+
StreamingResponse = typing.Union[StreamingResponse_Chunk, StreamingResponse_Done, StreamingResponse_Error]
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
from .types import (
|
4
|
+
BaseVoiceId,
|
5
|
+
CloneMode,
|
6
|
+
CreateVoiceRequest,
|
7
|
+
EmbeddingResponse,
|
8
|
+
EmbeddingSpecifier,
|
9
|
+
Gender,
|
10
|
+
GenderPresentation,
|
11
|
+
GetVoicesResponse,
|
12
|
+
IdSpecifier,
|
13
|
+
LocalizeDialect,
|
14
|
+
LocalizeEnglishDialect,
|
15
|
+
LocalizeFrenchDialect,
|
16
|
+
LocalizePortugueseDialect,
|
17
|
+
LocalizeSpanishDialect,
|
18
|
+
LocalizeTargetLanguage,
|
19
|
+
LocalizeVoiceRequest,
|
20
|
+
MixVoiceSpecifier,
|
21
|
+
MixVoicesRequest,
|
22
|
+
UpdateVoiceRequest,
|
23
|
+
Voice,
|
24
|
+
VoiceExpandOptions,
|
25
|
+
VoiceId,
|
26
|
+
VoiceMetadata,
|
27
|
+
Weight,
|
28
|
+
)
|
29
|
+
from .requests import (
|
30
|
+
CreateVoiceRequestParams,
|
31
|
+
EmbeddingResponseParams,
|
32
|
+
EmbeddingSpecifierParams,
|
33
|
+
GetVoicesResponseParams,
|
34
|
+
IdSpecifierParams,
|
35
|
+
LocalizeDialectParams,
|
36
|
+
LocalizeVoiceRequestParams,
|
37
|
+
MixVoiceSpecifierParams,
|
38
|
+
MixVoicesRequestParams,
|
39
|
+
UpdateVoiceRequestParams,
|
40
|
+
VoiceMetadataParams,
|
41
|
+
VoiceParams,
|
42
|
+
)
|
43
|
+
|
44
|
+
__all__ = [
|
45
|
+
"BaseVoiceId",
|
46
|
+
"CloneMode",
|
47
|
+
"CreateVoiceRequest",
|
48
|
+
"CreateVoiceRequestParams",
|
49
|
+
"EmbeddingResponse",
|
50
|
+
"EmbeddingResponseParams",
|
51
|
+
"EmbeddingSpecifier",
|
52
|
+
"EmbeddingSpecifierParams",
|
53
|
+
"Gender",
|
54
|
+
"GenderPresentation",
|
55
|
+
"GetVoicesResponse",
|
56
|
+
"GetVoicesResponseParams",
|
57
|
+
"IdSpecifier",
|
58
|
+
"IdSpecifierParams",
|
59
|
+
"LocalizeDialect",
|
60
|
+
"LocalizeDialectParams",
|
61
|
+
"LocalizeEnglishDialect",
|
62
|
+
"LocalizeFrenchDialect",
|
63
|
+
"LocalizePortugueseDialect",
|
64
|
+
"LocalizeSpanishDialect",
|
65
|
+
"LocalizeTargetLanguage",
|
66
|
+
"LocalizeVoiceRequest",
|
67
|
+
"LocalizeVoiceRequestParams",
|
68
|
+
"MixVoiceSpecifier",
|
69
|
+
"MixVoiceSpecifierParams",
|
70
|
+
"MixVoicesRequest",
|
71
|
+
"MixVoicesRequestParams",
|
72
|
+
"UpdateVoiceRequest",
|
73
|
+
"UpdateVoiceRequestParams",
|
74
|
+
"Voice",
|
75
|
+
"VoiceExpandOptions",
|
76
|
+
"VoiceId",
|
77
|
+
"VoiceMetadata",
|
78
|
+
"VoiceMetadataParams",
|
79
|
+
"VoiceParams",
|
80
|
+
"Weight",
|
81
|
+
]
|