o
    lWi%                     @   s   d dl Z d dlZd dlmZ ddlmZ ddlmZmZ ddl	m
Z
mZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ G dd dZG dd dZdS )    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)jsonable_encoder)RequestOptions)construct_type)ForbiddenError)NotFoundError)TooEarlyError)UnprocessableEntityError)HttpValidationErrorc                   @   V   e Zd ZdefddZejdddededej	e
 d	ejeeje   fd
dZdS )RawAudioClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r   g/var/www/html/asistente-voz-ia/venv/lib/python3.10/site-packages/elevenlabs/dubbing/audio/raw_client.py__init__      
zRawAudioClient.__init__Nrequest_options
dubbing_idlanguage_coder   returnc                #   sv    | j jjdt| dt| dd dttjt  f fdd}| V  W d   dS 1 s4w   Y  dS )	a  
        Returns dub as a streamed MP3 or MP4 file. If this dub has been edited using Dubbing Studio you need to use the resource render endpoint as this endpoint only returns the original automatic dub result.

        Parameters
        ----------
        dubbing_id : str
            ID of the dubbing project.

        language_code : str
            ID of the language.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.Iterator[HttpResponse[typing.Iterator[bytes]]]
            The dubbed audio or video file
        v1/dubbing//audio/GETmethodr   r"   c               	      sp  zd j   krdk r*n nd urddnd} t dd  j| dD dW S     j d	krHtt jt	tj
ttj
  d
d j dkrbtt jt	tj
ttj
  d
d j dkrztt jt	ttt  d
d j dkrtt jt	tj
ttj
  d
d  }W n ty   t j t j jdw t j t j|d)N   ,  
chunk_size   c                 s   s    | ]}|V  qd S r   r   .0_chunkr   r   r   	<genexpr>:   s    z6RawAudioClient.get.<locals>._stream.<locals>.<genexpr>r*   responsedata  type_object_headersbody      status_coder9   r:   )r?   getr   
iter_bytesreadr   dictr9   typingcastAnyr   jsonr   r   r   r   r   r   text_chunk_size_response_json	_responser   r   r   _stream5   st   







z#RawAudioClient.get.<locals>._streamN)r   httpx_clientstreamr	   r   rD   Iteratorbytesr   r    r!   r   rN   r   rL   r   r@      s   
;"zRawAudioClient.get)__name__
__module____qualname__r   r   
contextlibcontextmanagerstrrD   Optionalr
   rQ   r   rR   r@   r   r   r   r   r          r   c                   @   r   )AsyncRawAudioClientr   c                C   r   r   r   r   r   r   r   r   t   r   zAsyncRawAudioClient.__init__Nr   r    r!   r   r"   c             	     s   | j jjdt| dt| dd4 I dH " dttjt  f fdd}| I dH V  W d  I dH  dS 1 I dH sAw   Y  dS )	a  
        Returns dub as a streamed MP3 or MP4 file. If this dub has been edited using Dubbing Studio you need to use the resource render endpoint as this endpoint only returns the original automatic dub result.

        Parameters
        ----------
        dubbing_id : str
            ID of the dubbing project.

        language_code : str
            ID of the language.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]
            The dubbed audio or video file
        r#   r$   r%   r&   Nr"   c               	      sx  zd j   krdk r+n nd urddnd} t dd  j| d2 dW S   I d H   j d	krLtt jt	tj
ttj
  d
d j dkrftt jt	tj
ttj
  d
d j dkr~tt jt	ttt  d
d j dkrtt jt	tj
ttj
  d
d  }W n ty   t j t j jdw t j t j|d)Nr(   r)   r*   r+   c                 S  s   | z	3 d H W }|V  q6 d S r   r   r,   r   r   r   r/      s    z;AsyncRawAudioClient.get.<locals>._stream.<locals>.<genexpr>r0   r1   r4   r5   r8   r;   r<   r=   r>   )r?   r@   r   aiter_bytesareadr   rC   r9   rD   rE   rF   r   rG   r   r   r   r   r   r   rH   rI   rL   r   r   rN      sx   







z(AsyncRawAudioClient.get.<locals>._stream)r   rO   rP   r	   r   rD   AsyncIteratorrR   rS   r   rL   r   r@   w   s   <.zAsyncRawAudioClient.get)rT   rU   rV   r   r   rW   asynccontextmanagerrY   rD   rZ   r
   r_   r   rR   r@   r   r   r   r   r\   s   r[   r\   )rW   rD   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.http_responser   r   core.jsonable_encoderr	   core.request_optionsr
   core.unchecked_base_modelr   errors.forbidden_errorr   errors.not_found_errorr   errors.too_early_errorr   !errors.unprocessable_entity_errorr   types.http_validation_errorr   r   r\   r   r   r   r   <module>   s    _