@@ -439,7 +439,7 @@ def stream_audio(
439439 * ,
440440 convert_to_mpeg : typing .Optional [bool ] = OMIT ,
441441 request_options : typing .Optional [RequestOptions ] = None ,
442- ) -> None :
442+ ) -> typing . Iterator [ bytes ] :
443443 """
444444 Stream the audio from a project snapshot.
445445
@@ -458,14 +458,15 @@ def stream_audio(
458458 api_key="YOUR_API_KEY",
459459 )
460460 client.projects.stream_audio(
461- project_id="project_id",
462- project_snapshot_id="project_snapshot_id",
461+ project_id="string",
462+ project_snapshot_id="string",
463+ convert_to_mpeg=True,
463464 )
464465 """
465466 _request : typing .Dict [str , typing .Any ] = {}
466467 if convert_to_mpeg is not OMIT :
467468 _request ["convert_to_mpeg" ] = convert_to_mpeg
468- _response = self ._client_wrapper .httpx_client .request (
469+ with self ._client_wrapper .httpx_client .stream (
469470 method = "POST" ,
470471 url = urllib .parse .urljoin (
471472 f"{ self ._client_wrapper .get_base_url ()} /" ,
@@ -493,18 +494,21 @@ def stream_audio(
493494 else self ._client_wrapper .get_timeout (),
494495 retries = 0 ,
495496 max_retries = request_options .get ("max_retries" ) if request_options is not None else 0 , # type: ignore
496- )
497- if 200 <= _response .status_code < 300 :
498- return
499- if _response .status_code == 422 :
500- raise UnprocessableEntityError (
501- typing .cast (HttpValidationError , construct_type (type_ = HttpValidationError , object_ = _response .json ())) # type: ignore
502- )
503- try :
504- _response_json = _response .json ()
505- except JSONDecodeError :
506- raise ApiError (status_code = _response .status_code , body = _response .text )
507- raise ApiError (status_code = _response .status_code , body = _response_json )
497+ ) as _response :
498+ if 200 <= _response .status_code < 300 :
499+ for _chunk in _response .iter_bytes ():
500+ yield _chunk
501+ return
502+ _response .read ()
503+ if _response .status_code == 422 :
504+ raise UnprocessableEntityError (
505+ typing .cast (HttpValidationError , construct_type (type_ = HttpValidationError , object_ = _response .json ())) # type: ignore
506+ )
507+ try :
508+ _response_json = _response .json ()
509+ except JSONDecodeError :
510+ raise ApiError (status_code = _response .status_code , body = _response .text )
511+ raise ApiError (status_code = _response .status_code , body = _response_json )
508512
509513 def stream_archive (
510514 self , project_id : str , project_snapshot_id : str , * , request_options : typing .Optional [RequestOptions ] = None
@@ -1058,7 +1062,7 @@ async def stream_audio(
10581062 * ,
10591063 convert_to_mpeg : typing .Optional [bool ] = OMIT ,
10601064 request_options : typing .Optional [RequestOptions ] = None ,
1061- ) -> None :
1065+ ) -> typing . AsyncIterator [ bytes ] :
10621066 """
10631067 Stream the audio from a project snapshot.
10641068
@@ -1077,14 +1081,15 @@ async def stream_audio(
10771081 api_key="YOUR_API_KEY",
10781082 )
10791083 await client.projects.stream_audio(
1080- project_id="project_id",
1081- project_snapshot_id="project_snapshot_id",
1084+ project_id="string",
1085+ project_snapshot_id="string",
1086+ convert_to_mpeg=True,
10821087 )
10831088 """
10841089 _request : typing .Dict [str , typing .Any ] = {}
10851090 if convert_to_mpeg is not OMIT :
10861091 _request ["convert_to_mpeg" ] = convert_to_mpeg
1087- _response = await self ._client_wrapper .httpx_client .request (
1092+ async with self ._client_wrapper .httpx_client .stream (
10881093 method = "POST" ,
10891094 url = urllib .parse .urljoin (
10901095 f"{ self ._client_wrapper .get_base_url ()} /" ,
@@ -1112,18 +1117,21 @@ async def stream_audio(
11121117 else self ._client_wrapper .get_timeout (),
11131118 retries = 0 ,
11141119 max_retries = request_options .get ("max_retries" ) if request_options is not None else 0 , # type: ignore
1115- )
1116- if 200 <= _response .status_code < 300 :
1117- return
1118- if _response .status_code == 422 :
1119- raise UnprocessableEntityError (
1120- typing .cast (HttpValidationError , construct_type (type_ = HttpValidationError , object_ = _response .json ())) # type: ignore
1121- )
1122- try :
1123- _response_json = _response .json ()
1124- except JSONDecodeError :
1125- raise ApiError (status_code = _response .status_code , body = _response .text )
1126- raise ApiError (status_code = _response .status_code , body = _response_json )
1120+ ) as _response :
1121+ if 200 <= _response .status_code < 300 :
1122+ async for _chunk in _response .aiter_bytes ():
1123+ yield _chunk
1124+ return
1125+ await _response .aread ()
1126+ if _response .status_code == 422 :
1127+ raise UnprocessableEntityError (
1128+ typing .cast (HttpValidationError , construct_type (type_ = HttpValidationError , object_ = _response .json ())) # type: ignore
1129+ )
1130+ try :
1131+ _response_json = _response .json ()
1132+ except JSONDecodeError :
1133+ raise ApiError (status_code = _response .status_code , body = _response .text )
1134+ raise ApiError (status_code = _response .status_code , body = _response_json )
11271135
11281136 async def stream_archive (
11291137 self , project_id : str , project_snapshot_id : str , * , request_options : typing .Optional [RequestOptions ] = None
0 commit comments