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 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   )core)ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)jsonable_encoder)RequestOptions)'convert_and_respect_annotation_metadata)construct_type)UnprocessableEntityError)'AddPronunciationDictionaryResponseModel)1GetPronunciationDictionariesMetadataResponseModel)*GetPronunciationDictionaryMetadataResponse)HttpValidationError   )SBodyAddAPronunciationDictionaryV1PronunciationDictionariesAddFromRulesPostRulesItem)YBodyAddAPronunciationDictionaryV1PronunciationDictionariesAddFromRulesPostWorkspaceAccess)=PronunciationDictionariesCreateFromFileRequestWorkspaceAccess)(PronunciationDictionariesListRequestSort.c                   @     e Zd ZdefddZeeedddedeje	j
 deje d	eje d
eje dee fddZeedddeje dedeje d	eje d
eje dee fddZddded
eje dee fddZeedddedeje deje d
eje de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ddddddeje d eje d!eje d"eje d
eje dee fd#d$Z dS )%"RawPronunciationDictionariesClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r!   t/var/www/html/asistente-voz-ia/venv/lib/python3.10/site-packages/elevenlabs/pronunciation_dictionaries/raw_client.py__init__&      
z+RawPronunciationDictionariesClient.__init__Nfiledescriptionworkspace_accessrequest_optionsnamer&   r'   r(   r)   returnc          	   	   C   s   | j jjdd|||di |durd|ini |td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)au  
        Creates a new pronunciation dictionary from a lexicon .PLS file

        Parameters
        ----------
        name : str
            The name of the pronunciation dictionary, used for identification only.

        file : typing.Optional[core.File]
            See core.File for more documentation

        description : typing.Optional[str]
            A description of the pronunciation dictionary, used for identification only.

        workspace_access : typing.Optional[PronunciationDictionariesCreateFromFileRequestWorkspaceAccess]
            Should be one of 'admin', 'editor' or 'viewer'. If not provided, defaults to no access.

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

        Returns
        -------
        HttpResponse[AddPronunciationDictionaryResponseModel]
            Successful Response
        +v1/pronunciation-dictionaries/add-from-filePOSTr*   r'   r(   Nr&   Tmethoddatafilesr)   omitforce_multipart   ,  type_object_responser1     headersbodystatus_coder>   r?   )r   httpx_clientrequestOMITrA   typingcastr   r   jsonr	   r   dictr>   r   r   r   text	r    r*   r&   r'   r(   r)   	_response_data_response_jsonr!   r!   r"   create_from_file)   sP   "

z3RawPronunciationDictionariesClient.create_from_filer'   r(   r)   rulesc          	   	   C   s   | j jjddt|tjt d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  
        Creates a new pronunciation dictionary from provided rules.

        Parameters
        ----------
        rules : typing.Sequence[BodyAddAPronunciationDictionaryV1PronunciationDictionariesAddFromRulesPostRulesItem]
            List of pronunciation rules. Rule can be either:
                an alias rule: {'string_to_replace': 'a', 'type': 'alias', 'alias': 'b', }
                or a phoneme rule: {'string_to_replace': 'a', 'type': 'phoneme', 'phoneme': 'b', 'alphabet': 'ipa' }

        name : str
            The name of the pronunciation dictionary, used for identification only.

        description : typing.Optional[str]
            A description of the pronunciation dictionary, used for identification only.

        workspace_access : typing.Optional[BodyAddAPronunciationDictionaryV1PronunciationDictionariesAddFromRulesPostWorkspaceAccess]
            Should be one of 'admin', 'editor' or 'viewer'. If not provided, defaults to no access.

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

        Returns
        -------
        HttpResponse[AddPronunciationDictionaryResponseModel]
            Successful Response
        ,v1/pronunciation-dictionaries/add-from-rulesr-   writer9   
annotation	directionrP   r*   r'   r(   content-typeapplication/jsonr0   rG   r>   r)   r3   r5   r6   r7   r:   r<   r=   r@   )r   rB   rC   r   rE   Sequencer   rD   rA   rF   r   r   rG   r	   r   rH   r>   r   r   r   rI   	r    rP   r*   r'   r(   r)   rK   rL   rM   r!   r!   r"   create_from_rulest   sZ   &

z4RawPronunciationDictionariesClient.create_from_rulesr)   pronunciation_dictionary_idc             	   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  
        Get metadata for a pronunciation dictionary

        Parameters
        ----------
        pronunciation_dictionary_id : str
            The id of the pronunciation dictionary

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

        Returns
        -------
        HttpResponse[GetPronunciationDictionaryMetadataResponse]
            Successful Response
        v1/pronunciation-dictionaries/GETr0   r)   r5   r6   r7   r:   r<   r=   r@   )r   rB   rC   r
   rA   rE   rF   r   r   rG   r	   r   rH   r>   r   r   r   rI   r    r^   r)   rK   rL   rM   r!   r!   r"   get   s>   

z&RawPronunciationDictionariesClient.getarchivedr*   r)   re   c             	   C   s   | j jjdt| d||d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  
        Partially update the pronunciation dictionary without changing the version

        Parameters
        ----------
        pronunciation_dictionary_id : str
            The id of the pronunciation dictionary

        archived : typing.Optional[bool]
            The name of the pronunciation dictionary, used for identification only.

        name : typing.Optional[str]
            The name of the pronunciation dictionary, used for identification only.

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

        Returns
        -------
        HttpResponse[GetPronunciationDictionaryMetadataResponse]
            Successful Response
        r_   PATCHre   r*   rW   rX   rY   r5   r6   r7   r:   r<   r=   r@   )r   rB   rC   r
   rD   rA   rE   rF   r   r   rG   r	   r   rH   r>   r   r   r   rI   r    r^   re   r*   r)   rK   rL   rM   r!   r!   r"   update   sJ   

z)RawPronunciationDictionariesClient.updatedictionary_id
version_idc                #   sx    | j jjdt| dt| ddd dttjt  f fdd}| V  W d	   d	S 1 s5w   Y  d	S )
a  
        Get a PLS file with a pronunciation dictionary version rules

        Parameters
        ----------
        dictionary_id : str
            The id of the pronunciation dictionary

        version_id : str
            The id of the pronunciation dictionary version

        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 PLS file containing pronunciation dictionary rules
        r_   /	/downloadr`   ra   r+   c               	      s   zKd 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rFtt jt	t
tt
  d
d  }W n ty^   t j t j jdw t j t j|d)Nr5   r6   
chunk_size   c                 s   s    | ]}|V  qd S r   r!   .0_chunkr!   r!   r"   	<genexpr>b  s    zORawPronunciationDictionariesClient.download.<locals>._stream.<locals>.<genexpr>rn   r:   r<   r7   r=   r@   )rA   rc   r	   
iter_bytesreadr   rH   r>   rE   rF   r   r   rG   r   r   rI   _chunk_sizerM   rK   r)   r!   r"   _stream]  s2   

z<RawPronunciationDictionariesClient.download.<locals>._streamN)r   rB   streamr
   r	   rE   Iteratorbytesr    rj   rk   r)   rz   r!   ry   r"   download@  s   
"z+RawPronunciationDictionariesClient.downloadcursor	page_sizesortsort_directionr)   r   r   r   r   c          	   	   C   s   | j jjdd||||d|d}z>d|j  krdk r1n ntttt| d}t	||dW S |jd	krIt
t|jtttt| dd
| }W n tya   t|jt|j|jdw t|jt|j|d)a  
        Get a list of the pronunciation dictionaries you have access to and their metadata

        Parameters
        ----------
        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

        page_size : typing.Optional[int]
            How many pronunciation dictionaries to return at maximum. Can not exceed 100, defaults to 30.

        sort : typing.Optional[PronunciationDictionariesListRequestSort]
            Which field to sort by, one of 'created_at_unix' or 'name'.

        sort_direction : typing.Optional[str]
            Which direction to sort the voices in. 'ascending' or 'descending'.

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

        Returns
        -------
        HttpResponse[GetPronunciationDictionariesMetadataResponseModel]
            Successful Response
        v1/pronunciation-dictionariesr`   r   r   r   r   r0   paramsr)   r5   r6   r7   r:   r<   r=   r@   )r   rB   rC   rA   rE   rF   r   r   rG   r	   r   rH   r>   r   r   r   rI   	r    r   r   r   r   r)   rK   rL   rM   r!   r!   r"   listy  sH   "

z'RawPronunciationDictionariesClient.list)!__name__
__module____qualname__r   r#   rD   strrE   Optionalr   Filer   r   r	   r   rN   rZ   r   r   r\   r   rc   boolri   
contextlibcontextmanagerr|   r}   r   intr   r   r   r!   r!   r!   r"   r   %   s    

P	

V
6
E;r   c                   @   r   )%'AsyncRawPronunciationDictionariesClientr   c                C   r   r   r   r   r!   r!   r"   r#     r$   z0AsyncRawPronunciationDictionariesClient.__init__Nr%   r*   r&   r'   r(   r)   r+   c          	   	      s   | j jjdd|||di |durd|ini |td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)az  
        Creates a new pronunciation dictionary from a lexicon .PLS file

        Parameters
        ----------
        name : str
            The name of the pronunciation dictionary, used for identification only.

        file : typing.Optional[core.File]
            See core.File for more documentation

        description : typing.Optional[str]
            A description of the pronunciation dictionary, used for identification only.

        workspace_access : typing.Optional[PronunciationDictionariesCreateFromFileRequestWorkspaceAccess]
            Should be one of 'admin', 'editor' or 'viewer'. If not provided, defaults to no access.

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

        Returns
        -------
        AsyncHttpResponse[AddPronunciationDictionaryResponseModel]
            Successful Response
        r,   r-   r.   Nr&   Tr/   r5   r6   r7   r:   r<   r=   r@   )r   rB   rC   rD   rA   rE   rF   r   r   rG   r   r   rH   r>   r   r   r   rI   rJ   r!   r!   r"   rN     sR   "

z8AsyncRawPronunciationDictionariesClient.create_from_filerO   rP   c          	   	      s   | j jjddt|tjt d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  
        Creates a new pronunciation dictionary from provided rules.

        Parameters
        ----------
        rules : typing.Sequence[BodyAddAPronunciationDictionaryV1PronunciationDictionariesAddFromRulesPostRulesItem]
            List of pronunciation rules. Rule can be either:
                an alias rule: {'string_to_replace': 'a', 'type': 'alias', 'alias': 'b', }
                or a phoneme rule: {'string_to_replace': 'a', 'type': 'phoneme', 'phoneme': 'b', 'alphabet': 'ipa' }

        name : str
            The name of the pronunciation dictionary, used for identification only.

        description : typing.Optional[str]
            A description of the pronunciation dictionary, used for identification only.

        workspace_access : typing.Optional[BodyAddAPronunciationDictionaryV1PronunciationDictionariesAddFromRulesPostWorkspaceAccess]
            Should be one of 'admin', 'editor' or 'viewer'. If not provided, defaults to no access.

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

        Returns
        -------
        AsyncHttpResponse[AddPronunciationDictionaryResponseModel]
            Successful Response
        rQ   r-   rR   rS   rV   rW   rX   rY   Nr5   r6   r7   r:   r<   r=   r@   )r   rB   rC   r   rE   rZ   r   rD   rA   rF   r   r   rG   r   r   rH   r>   r   r   r   rI   r[   r!   r!   r"   r\     s\   &

z9AsyncRawPronunciationDictionariesClient.create_from_rulesr]   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  
        Get metadata for a pronunciation dictionary

        Parameters
        ----------
        pronunciation_dictionary_id : str
            The id of the pronunciation dictionary

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

        Returns
        -------
        AsyncHttpResponse[GetPronunciationDictionaryMetadataResponse]
            Successful Response
        r_   r`   ra   Nr5   r6   r7   r:   r<   r=   r@   )r   rB   rC   r
   rA   rE   rF   r   r   rG   r   r   rH   r>   r   r   r   rI   rb   r!   r!   r"   rc   e  s@   

z+AsyncRawPronunciationDictionariesClient.getrd   re   c             	      s   | j jjdt| 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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  
        Partially update the pronunciation dictionary without changing the version

        Parameters
        ----------
        pronunciation_dictionary_id : str
            The id of the pronunciation dictionary

        archived : typing.Optional[bool]
            The name of the pronunciation dictionary, used for identification only.

        name : typing.Optional[str]
            The name of the pronunciation dictionary, used for identification only.

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

        Returns
        -------
        AsyncHttpResponse[GetPronunciationDictionaryMetadataResponse]
            Successful Response
        r_   rf   rg   rW   rX   rY   Nr5   r6   r7   r:   r<   r=   r@   )r   rB   rC   r
   rD   rA   rE   rF   r   r   rG   r   r   rH   r>   r   r   r   rI   rh   r!   r!   r"   ri     sL   

z.AsyncRawPronunciationDictionariesClient.updaterj   rk   c             	     s   | j jjdt| dt| d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 sBw   Y  dS )
a  
        Get a PLS file with a pronunciation dictionary version rules

        Parameters
        ----------
        dictionary_id : str
            The id of the pronunciation dictionary

        version_id : str
            The id of the pronunciation dictionary version

        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 PLS file containing pronunciation dictionary rules
        r_   rl   rm   r`   ra   Nr+   c               	      s   zNd 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rJtt jt	t
tt
  d
d  }W n tyb   t j t j jdw t j t j|d)Nr5   r6   rn   ro   c                 S  s   | z	3 d H W }|V  q6 d S r   r!   rp   r!   r!   r"   rs     s    zTAsyncRawPronunciationDictionariesClient.download.<locals>._stream.<locals>.<genexpr>rt   r:   r<   r7   r=   r@   )rA   rc   r   aiter_bytesareadr   rH   r>   rE   rF   r   r   rG   r   r   rI   rw   ry   r!   r"   rz     s6   

zAAsyncRawPronunciationDictionariesClient.download.<locals>._stream)r   rB   r{   r
   r   rE   AsyncIteratorr}   r~   r!   ry   r"   r     s   .z0AsyncRawPronunciationDictionariesClient.downloadr   r   r   r   r   c          	   	      s   | j jjdd||||d|dI dH }z>d|j  kr dk r5n ntttt| d}t	||d	W S |jd
krMt
t|jtttt| dd| }W n tye   t|jt|j|jdw t|jt|j|d)a  
        Get a list of the pronunciation dictionaries you have access to and their metadata

        Parameters
        ----------
        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

        page_size : typing.Optional[int]
            How many pronunciation dictionaries to return at maximum. Can not exceed 100, defaults to 30.

        sort : typing.Optional[PronunciationDictionariesListRequestSort]
            Which field to sort by, one of 'created_at_unix' or 'name'.

        sort_direction : typing.Optional[str]
            Which direction to sort the voices in. 'ascending' or 'descending'.

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

        Returns
        -------
        AsyncHttpResponse[GetPronunciationDictionariesMetadataResponseModel]
            Successful Response
        r   r`   r   r   Nr5   r6   r7   r:   r<   r=   r@   )r   rB   rC   rA   rE   rF   r   r   rG   r   r   rH   r>   r   r   r   rI   r   r!   r!   r"   r     sJ   "

z,AsyncRawPronunciationDictionariesClient.list)!r   r   r   r   r#   rD   r   rE   r   r   r   r   r   r   r   rN   rZ   r   r   r\   r   rc   r   ri   r   asynccontextmanagerr   r}   r   r   r   r   r   r!   r!   r!   r"   r     s    

P	

V
6
E<r   )-r   rE   json.decoderr    r   core.api_errorr   core.client_wrapperr   r   core.http_responser   r	   core.jsonable_encoderr
   core.request_optionsr   core.serializationr   core.unchecked_base_modelr   !errors.unprocessable_entity_errorr   1types.add_pronunciation_dictionary_response_modelr   <types.get_pronunciation_dictionaries_metadata_response_modelr   4types.get_pronunciation_dictionary_metadata_responser   types.http_validation_errorr   gtypes.body_add_a_pronunciation_dictionary_v_1_pronunciation_dictionaries_add_from_rules_post_rules_itemr   mtypes.body_add_a_pronunciation_dictionary_v_1_pronunciation_dictionaries_add_from_rules_post_workspace_accessr   Jtypes.pronunciation_dictionaries_create_from_file_request_workspace_accessr   2types.pronunciation_dictionaries_list_request_sortr   rF   AnyrD   r   r   r!   r!   r!   r"   <module>   s4      