o
    lWi~|                     @   s
  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 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$ e %e j&d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)UnprocessableEntityError)DubbingRenderResponseModel)DubbingResource)HttpValidationError)
RenderType)SegmentDubResponse)SegmentMigrationResponse)SegmentTranscriptionResponse)SegmentTranslationResponse   )ResourceRenderRequestLanguage.c                   @   b  e Zd ZdefddZdddedeje de	e
 fd	d
Zdddedeje dedeje de	e f
ddZdddedeje deje de	e fddZedddedeje dejeje  deje de	e f
ddZedddedeje dejeje  deje de	e f
ddZedddedededeje deje de	e fddZdS )RawResourceClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r    j/var/www/html/asistente-voz-ia/venv/lib/python3.10/site-packages/elevenlabs/dubbing/resource/raw_client.py__init__      
zRawResourceClient.__init__Nrequest_options
dubbing_idr%   returnc             	   C   s   | j jjdt| d|d}z>d|j  krdk r0n ntttt|	 d}t
||dW S |jdkrHtt|jtttt|	 dd	|	 }W n ty`   t|jt|j|jd
w t|jt|j|d
)a  
        Given a dubbing ID generated from the '/v1/dubbing' endpoint with studio enabled, returns the dubbing resource.

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

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[DubbingResource]
            Successful Response
        v1/dubbing/resource/GETmethodr%      ,  type_object_responsedata  headersbodystatus_coder6   r7   )r   httpx_clientrequestr	   r9   typingcastr   r   jsonr   r   dictr6   r   r   r   textr   r&   r%   	_response_data_response_jsonr    r    r!   get   s>   

zRawResourceClient.getsegment_ids
speaker_idc             	   C      | j jjdt| dd||dddi|td}z>d|j  kr$d	k r9n nttt	t|
 d
}t||dW S |jdkrQtt|jttt	t|
 d
d|
 }W n tyi   t|jt|j|jdw t|jt|j|d)a  
        Change the attribution of one or more segments to a different speaker.

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

        segment_ids : typing.Sequence[str]

        speaker_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[SegmentMigrationResponse]
            Successful Response
        r(   /migrate-segmentsPOSTrF   rG   content-typeapplication/jsonr+   r>   r6   r%   omitr,   r-   r.   r1   r4   r5   r8   )r   r:   r;   r	   OMITr9   r<   r=   r   r   r>   r   r   r?   r6   r   r   r   r@   r   r&   rF   rG   r%   rB   rC   rD   r    r    r!   migrate_segmentsQ   sJ   

z"RawResourceClient.migrate_segmentssegmentsc             	   C   s   | j jjdt| ddd|iddi|td}z>d|j  kr#d	k r8n nttt	t|
 d
}t||dW S |jdkrPtt|jttt	t|
 d
d|
 }W n tyh   t|jt|j|jdw t|jt|j|d)a%  
        Regenerate the transcriptions for the specified segments. Does not automatically regenerate translations or dubs.

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

        segments : typing.Sequence[str]
            Transcribe this specific list of segments.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[SegmentTranscriptionResponse]
            Successful Response
        r(   /transcriberJ   rS   rL   rM   rN   r,   r-   r.   r1   r4   r5   r8   )r   r:   r;   r	   rP   r9   r<   r=   r   r   r>   r   r   r?   r6   r   r   r   r@   r   r&   rS   r%   rB   rC   rD   r    r    r!   
transcribe   sH   

zRawResourceClient.transcribe	languagesr%   rX   c             	   C   rH   )a  
        Regenerate the translations for either the entire resource or the specified segments/languages. Will automatically transcribe missing transcriptions. Will not automatically regenerate the dubs.

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

        segments : typing.Sequence[str]
            Translate only this list of segments.

        languages : typing.Optional[typing.Sequence[str]]
            Translate only these languages for each segment.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[SegmentTranslationResponse]
            Successful Response
        r(   
/translaterJ   rS   rX   rL   rM   rN   r,   r-   r.   r1   r4   r5   r8   )r   r:   r;   r	   rP   r9   r<   r=   r   r   r>   r   r   r?   r6   r   r   r   r@   r   r&   rS   rX   r%   rB   rC   rD   r    r    r!   	translate   J   

zRawResourceClient.translatec             	   C   rH   )a  
        Regenerate the dubs for either the entire resource or the specified segments/languages. Will automatically transcribe and translate any missing transcriptions and translations.

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

        segments : typing.Sequence[str]
            Dub only this list of segments.

        languages : typing.Optional[typing.Sequence[str]]
            Dub only these languages for each segment.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[SegmentDubResponse]
            Successful Response
        r(   /dubrJ   rZ   rL   rM   rN   r,   r-   r.   r1   r4   r5   r8   )r   r:   r;   r	   rP   r9   r<   r=   r   r   r>   r   r   r?   r6   r   r   r   r@   r[   r    r    r!   dub  r]   zRawResourceClient.dubnormalize_volumer%   languagerender_typera   c          	   	   C   s   | j jjdt| dt| d||dddi|td}z>d|j  kr(d	k r=n nttt	t|
 d
}t||dW S |jdkrUtt|jttt	t|
 d
d|
 }W n tym   t|jt|j|jdw t|jt|j|d)a  
        Regenerate the output media for a language using the latest Studio state. Please ensure all segments have been dubbed before rendering, otherwise they will be omitted. Renders are generated asynchronously, and to check the status of all renders please use the 'Get Dubbing Resource' endpoint.

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

        language : ResourceRenderRequestLanguage
            The target language code to render, eg. 'es'. To render the source track use 'original'.

        render_type : RenderType
            The type of the render. One of ['mp4', 'aac', 'mp3', 'wav', 'aaf', 'tracks_zip', 'clips_zip']

        normalize_volume : typing.Optional[bool]
            Whether to normalize the volume of the rendered audio.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[DubbingRenderResponseModel]
            Successful Response
        r(   /render/rJ   rc   ra   rL   rM   rN   r,   r-   r.   r1   r4   r5   r8   )r   r:   r;   r	   rP   r9   r<   r=   r   r   r>   r   r   r?   r6   r   r   r   r@   	r   r&   rb   rc   ra   r%   rB   rC   rD   r    r    r!   render^  sJ   "

zRawResourceClient.render)__name__
__module____qualname__r   r"   strr<   Optionalr
   r   r   rE   Sequencer   rR   r   rV   rP   r   r\   r   r_   r   r   boolr   rg   r    r    r    r!   r          
8
H
E
J
Kr   c                   @   r   )AsyncRawResourceClientr   c                C   r   r   r   r   r    r    r!   r"     r#   zAsyncRawResourceClient.__init__Nr$   r&   r%   r'   c             	      s   | j jjdt| d|dI dH }z>d|j  krdk r4n ntttt|	 d}t
||dW S |jd	krLtt|jtttt|	 dd
|	 }W n tyd   t|jt|j|jdw t|jt|j|d)a  
        Given a dubbing ID generated from the '/v1/dubbing' endpoint with studio enabled, returns the dubbing resource.

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

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[DubbingResource]
            Successful Response
        r(   r)   r*   Nr,   r-   r.   r1   r4   r5   r8   )r   r:   r;   r	   r9   r<   r=   r   r   r>   r   r   r?   r6   r   r   r   r@   rA   r    r    r!   rE     s@   

zAsyncRawResourceClient.getrF   rG   c             	         | j jjdt| dd||dddi|tdI dH }z>d	|j  kr(d
k r=n nttt	t|
 d}t||dW S |jdkrUtt|jttt	t|
 dd|
 }W n tym   t|jt|j|jdw t|jt|j|d)a  
        Change the attribution of one or more segments to a different speaker.

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

        segment_ids : typing.Sequence[str]

        speaker_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[SegmentMigrationResponse]
            Successful Response
        r(   rI   rJ   rK   rL   rM   rN   Nr,   r-   r.   r1   r4   r5   r8   )r   r:   r;   r	   rP   r9   r<   r=   r   r   r>   r   r   r?   r6   r   r   r   r@   rQ   r    r    r!   rR     sL   

z'AsyncRawResourceClient.migrate_segmentsrS   c             	      s   | j jjdt| ddd|iddi|tdI dH }z>d	|j  kr'd
k r<n nttt	t|
 d}t||dW S |jdkrTtt|jttt	t|
 dd|
 }W n tyl   t|jt|j|jdw t|jt|j|d)a*  
        Regenerate the transcriptions for the specified segments. Does not automatically regenerate translations or dubs.

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

        segments : typing.Sequence[str]
            Transcribe this specific list of segments.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[SegmentTranscriptionResponse]
            Successful Response
        r(   rT   rJ   rS   rL   rM   rN   Nr,   r-   r.   r1   r4   r5   r8   )r   r:   r;   r	   rP   r9   r<   r=   r   r   r>   r   r   r?   r6   r   r   r   r@   rU   r    r    r!   rV   !  sJ   

z!AsyncRawResourceClient.transcriberW   rX   c             	      rq   )a  
        Regenerate the translations for either the entire resource or the specified segments/languages. Will automatically transcribe missing transcriptions. Will not automatically regenerate the dubs.

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

        segments : typing.Sequence[str]
            Translate only this list of segments.

        languages : typing.Optional[typing.Sequence[str]]
            Translate only these languages for each segment.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[SegmentTranslationResponse]
            Successful Response
        r(   rY   rJ   rZ   rL   rM   rN   Nr,   r-   r.   r1   r4   r5   r8   )r   r:   r;   r	   rP   r9   r<   r=   r   r   r>   r   r   r?   r6   r   r   r   r@   r[   r    r    r!   r\   a  L   

z AsyncRawResourceClient.translatec             	      rq   )a  
        Regenerate the dubs for either the entire resource or the specified segments/languages. Will automatically transcribe and translate any missing transcriptions and translations.

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

        segments : typing.Sequence[str]
            Dub only this list of segments.

        languages : typing.Optional[typing.Sequence[str]]
            Dub only these languages for each segment.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[SegmentDubResponse]
            Successful Response
        r(   r^   rJ   rZ   rL   rM   rN   Nr,   r-   r.   r1   r4   r5   r8   )r   r:   r;   r	   rP   r9   r<   r=   r   r   r>   r   r   r?   r6   r   r   r   r@   r[   r    r    r!   r_     rr   zAsyncRawResourceClient.dubr`   rb   rc   ra   c          	   	      s   | j jjdt| dt| d||dddi|tdI dH }z>d	|j  kr,d
k rAn nttt	t|
 d}t||dW S |jdkrYtt|jttt	t|
 dd|
 }W n tyq   t|jt|j|jdw t|jt|j|d)a  
        Regenerate the output media for a language using the latest Studio state. Please ensure all segments have been dubbed before rendering, otherwise they will be omitted. Renders are generated asynchronously, and to check the status of all renders please use the 'Get Dubbing Resource' endpoint.

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

        language : ResourceRenderRequestLanguage
            The target language code to render, eg. 'es'. To render the source track use 'original'.

        render_type : RenderType
            The type of the render. One of ['mp4', 'aac', 'mp3', 'wav', 'aaf', 'tracks_zip', 'clips_zip']

        normalize_volume : typing.Optional[bool]
            Whether to normalize the volume of the rendered audio.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[DubbingRenderResponseModel]
            Successful Response
        r(   rd   rJ   re   rL   rM   rN   Nr,   r-   r.   r1   r4   r5   r8   )r   r:   r;   r	   rP   r9   r<   r=   r   r   r>   r   r   r?   r6   r   r   r   r@   rf   r    r    r!   rg     sL   "

zAsyncRawResourceClient.render)rh   ri   rj   r   r"   rk   r<   rl   r
   r   r   rE   rm   r   rR   r   rV   rP   r   r\   r   r_   r   r   rn   r   rg   r    r    r    r!   rp     ro   rp   )*r<   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.http_responser   r   core.jsonable_encoderr	   core.request_optionsr
   core.unchecked_base_modelr   !errors.unprocessable_entity_errorr   #types.dubbing_render_response_modelr   types.dubbing_resourcer   types.http_validation_errorr   types.render_typer   types.segment_dub_responser    types.segment_migration_responser   $types.segment_transcription_responser   "types.segment_translation_responser   &types.resource_render_request_languager   r=   AnyrP   r   rp   r    r    r    r!   <module>   s0      