|
15 | 15 | from ..errors.bad_request_error import BadRequestError
|
16 | 16 | from ..errors.payment_required_error import PaymentRequiredError
|
17 | 17 | from ...core.jsonable_encoder import jsonable_encoder
|
| 18 | +from ..errors.unauthorized_error import UnauthorizedError |
18 | 19 | from ...core.client_wrapper import AsyncClientWrapper
|
19 | 20 |
|
20 | 21 | # this is used as the default value for optional parameters
|
@@ -277,6 +278,82 @@ def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] =
|
277 | 278 | raise ApiError(status_code=_response.status_code, body=_response.text)
|
278 | 279 | raise ApiError(status_code=_response.status_code, body=_response_json)
|
279 | 280 |
|
| 281 | + def download_sample( |
| 282 | + self, id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 283 | + ) -> typing.Iterator[bytes]: |
| 284 | + """ |
| 285 | + Download a personal (cloned) voice sample |
| 286 | +
|
| 287 | + Parameters |
| 288 | + ---------- |
| 289 | + id : str |
| 290 | + The ID of the voice to download sample for |
| 291 | +
|
| 292 | + request_options : typing.Optional[RequestOptions] |
| 293 | + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. |
| 294 | +
|
| 295 | + Yields |
| 296 | + ------ |
| 297 | + typing.Iterator[bytes] |
| 298 | + Voice sample audio file |
| 299 | + """ |
| 300 | + with self._client_wrapper.httpx_client.stream( |
| 301 | + f"v1/voices/{jsonable_encoder(id)}/sample", |
| 302 | + method="GET", |
| 303 | + request_options=request_options, |
| 304 | + ) as _response: |
| 305 | + try: |
| 306 | + if 200 <= _response.status_code < 300: |
| 307 | + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None |
| 308 | + for _chunk in _response.iter_bytes(chunk_size=_chunk_size): |
| 309 | + yield _chunk |
| 310 | + return |
| 311 | + _response.read() |
| 312 | + if _response.status_code == 400: |
| 313 | + raise BadRequestError( |
| 314 | + typing.cast( |
| 315 | + typing.Optional[typing.Any], |
| 316 | + parse_obj_as( |
| 317 | + type_=typing.Optional[typing.Any], # type: ignore |
| 318 | + object_=_response.json(), |
| 319 | + ), |
| 320 | + ) |
| 321 | + ) |
| 322 | + if _response.status_code == 401: |
| 323 | + raise UnauthorizedError( |
| 324 | + typing.cast( |
| 325 | + typing.Optional[typing.Any], |
| 326 | + parse_obj_as( |
| 327 | + type_=typing.Optional[typing.Any], # type: ignore |
| 328 | + object_=_response.json(), |
| 329 | + ), |
| 330 | + ) |
| 331 | + ) |
| 332 | + if _response.status_code == 404: |
| 333 | + raise NotFoundError( |
| 334 | + typing.cast( |
| 335 | + typing.Optional[typing.Any], |
| 336 | + parse_obj_as( |
| 337 | + type_=typing.Optional[typing.Any], # type: ignore |
| 338 | + object_=_response.json(), |
| 339 | + ), |
| 340 | + ) |
| 341 | + ) |
| 342 | + if _response.status_code == 500: |
| 343 | + raise InternalServerError( |
| 344 | + typing.cast( |
| 345 | + typing.Optional[typing.Any], |
| 346 | + parse_obj_as( |
| 347 | + type_=typing.Optional[typing.Any], # type: ignore |
| 348 | + object_=_response.json(), |
| 349 | + ), |
| 350 | + ) |
| 351 | + ) |
| 352 | + _response_json = _response.json() |
| 353 | + except JSONDecodeError: |
| 354 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 355 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 356 | + |
280 | 357 |
|
281 | 358 | class AsyncVoicesClient:
|
282 | 359 | def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
@@ -557,3 +634,79 @@ async def main() -> None:
|
557 | 634 | except JSONDecodeError:
|
558 | 635 | raise ApiError(status_code=_response.status_code, body=_response.text)
|
559 | 636 | raise ApiError(status_code=_response.status_code, body=_response_json)
|
| 637 | + |
| 638 | + async def download_sample( |
| 639 | + self, id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 640 | + ) -> typing.AsyncIterator[bytes]: |
| 641 | + """ |
| 642 | + Download a personal (cloned) voice sample |
| 643 | +
|
| 644 | + Parameters |
| 645 | + ---------- |
| 646 | + id : str |
| 647 | + The ID of the voice to download sample for |
| 648 | +
|
| 649 | + request_options : typing.Optional[RequestOptions] |
| 650 | + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. |
| 651 | +
|
| 652 | + Yields |
| 653 | + ------ |
| 654 | + typing.AsyncIterator[bytes] |
| 655 | + Voice sample audio file |
| 656 | + """ |
| 657 | + async with self._client_wrapper.httpx_client.stream( |
| 658 | + f"v1/voices/{jsonable_encoder(id)}/sample", |
| 659 | + method="GET", |
| 660 | + request_options=request_options, |
| 661 | + ) as _response: |
| 662 | + try: |
| 663 | + if 200 <= _response.status_code < 300: |
| 664 | + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None |
| 665 | + async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size): |
| 666 | + yield _chunk |
| 667 | + return |
| 668 | + await _response.aread() |
| 669 | + if _response.status_code == 400: |
| 670 | + raise BadRequestError( |
| 671 | + typing.cast( |
| 672 | + typing.Optional[typing.Any], |
| 673 | + parse_obj_as( |
| 674 | + type_=typing.Optional[typing.Any], # type: ignore |
| 675 | + object_=_response.json(), |
| 676 | + ), |
| 677 | + ) |
| 678 | + ) |
| 679 | + if _response.status_code == 401: |
| 680 | + raise UnauthorizedError( |
| 681 | + typing.cast( |
| 682 | + typing.Optional[typing.Any], |
| 683 | + parse_obj_as( |
| 684 | + type_=typing.Optional[typing.Any], # type: ignore |
| 685 | + object_=_response.json(), |
| 686 | + ), |
| 687 | + ) |
| 688 | + ) |
| 689 | + if _response.status_code == 404: |
| 690 | + raise NotFoundError( |
| 691 | + typing.cast( |
| 692 | + typing.Optional[typing.Any], |
| 693 | + parse_obj_as( |
| 694 | + type_=typing.Optional[typing.Any], # type: ignore |
| 695 | + object_=_response.json(), |
| 696 | + ), |
| 697 | + ) |
| 698 | + ) |
| 699 | + if _response.status_code == 500: |
| 700 | + raise InternalServerError( |
| 701 | + typing.cast( |
| 702 | + typing.Optional[typing.Any], |
| 703 | + parse_obj_as( |
| 704 | + type_=typing.Optional[typing.Any], # type: ignore |
| 705 | + object_=_response.json(), |
| 706 | + ), |
| 707 | + ) |
| 708 | + ) |
| 709 | + _response_json = _response.json() |
| 710 | + except JSONDecodeError: |
| 711 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 712 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
0 commit comments