o
    "iHN                     @   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 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 zd dlmZ W n eyg   d dlZY nw e  e j!dZ"G dd dZ#G dd dZ$dS )    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)jsonable_encoder)remove_none_from_dict)RequestOptions)UnprocessableEntityError)Age)Gender)HttpValidationError)Voice) VoiceGenerationParameterResponse.c                   @      e Zd ZdefddZdddeje defdd	Z	ddd
e
dededededeje deje fddZedddedededejejeef  deje defddZdS )VoiceGenerationClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r   f/var/www/html/voicebot/backend/venv/lib/python3.10/site-packages/elevenlabs/voice_generation/client.py__init__      
zVoiceGenerationClient.__init__Nrequest_optionsr   returnc                C   s  | j jjdtj| j   ddt|dur|dndtt	i | j 
 |dur/|di ni |durC|ddurC|dndd	|durN|d
nd	d}d|j  kr]dk rgn ntt| S z| }W n ty|   t|j|jdw t|j|d)a  
        Get possible parameters for the /v1/voice-generation/generate-voice endpoint.

        Parameters:
            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.voice_generation.generate_parameters()
        GET/-v1/voice-generation/generate-voice/parametersNadditional_query_parametersadditional_headerstimeout_in_seconds<   r   max_retriesparamsheaderstimeoutretriesr'      ,  status_codebodyr   httpx_clientrequesturllibparseurljoinget_base_urlr   getr   get_headersr0   pydanticparse_obj_asr   jsonr   r   textr   r   	_response_response_jsonr   r   r   generate_parameters    s>   	
z)VoiceGenerationClient.generate_parametersgenderaccentageaccent_strengthr>   c          
      c   s   | j jjdtj| j   ddt|dur|dnd|du s)|ddu r3t|||||dni t|||||dtt	|di tt	i | j 
 |durZ|di ni |durn|d	durn|d	nd
d|dury|dnddB}d|j  krdk rn n| D ]}|V  q	 W d   dS |  z| }	W n ty   t|j|jdw t|j|	d1 sw   Y  dS )aO  
        Generate a random voice based on parameters. This method returns a generated_voice_id in the response header, and a sample of the voice in the body. If you like the generated voice call /v1/voice-generation/create-voice with the generated_voice_id to create the voice.

        Parameters:
            - gender: Gender. Category code corresponding to the gender of the generated voice. Possible values: female, male.

            - accent: str. Category code corresponding to the accent of the generated voice. Possible values: american, british, african, australian, indian.

            - age: Age. Category code corresponding to the age of the generated voice. Possible values: young, middle_aged, old.

            - accent_strength: float. The strength of the accent of the generated voice. Has to be between 0.3 and 2.0.

            - text: str. Text to generate, text length has to be between 100 and 1000.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.voice_generation.generate(
            gender="male",
            accent="string",
            age="young",
            accent_strength=1.1,
            text="string",
        )
        POSTr!   "v1/voice-generation/generate-voiceNr#   additional_body_parametersrC   rD   rE   rF   r>   r$   r%   r&   r   r'   r)   r=   r*   r+   r,   r'   r-   r.   r/   )r   r3   streamr5   r6   r7   r8   r   r9   r   r:   r0   
iter_bytesreadr=   r   r   r>   
r   rC   rD   rE   rF   r>   r   r@   _chunkrA   r   r   r   generateN   s^   '	
"zVoiceGenerationClient.generatelabelsr   
voice_namevoice_descriptiongenerated_voice_idrS   c          	      C   s~  |||d}|t ur||d< | jjjdtj| j  ddt|dur)|	dnd|du s6|	ddu r:t|ni t|tt
|	di tt
i | j |dur[|	d	i ni |duro|	d
duro|	d
ndd|durz|	dndd}d|j  krdk rn ntt| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a_  
        Create a previously generated voice. This endpoint should be called after you fetched a generated_voice_id using /v1/voice-generation/generate-voice.

        Parameters:
            - voice_name: str. Name to use for the created voice.

            - voice_description: str. Description to use for the created voice.

            - generated_voice_id: str. The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.

            - labels: typing.Optional[typing.Dict[str, str]]. Optional, metadata to add to the created voice. Defaults to None.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.voice_generation.create_a_previously_generated_voice(
            voice_name="voice_name",
            voice_description="voice_description",
            generated_voice_id="generated_voice_id",
        )
        rT   rU   rV   rS   rG   r!    v1/voice-generation/create-voiceNr#   rI   r$   r%   r&   r   r'   rK   r-   r.     r/   OMITr   r3   r4   r5   r6   r7   r8   r   r9   r   r:   r0   r;   r<   r   r=   r
   r   r   r   r>   	r   rT   rU   rV   rS   r   _requestr@   rA   r   r   r   #create_a_previously_generated_voice   sX   #	

z9VoiceGenerationClient.create_a_previously_generated_voice)__name__
__module____qualname__r   r   typingOptionalr	   r   rB   r   strr   floatIteratorbytesrQ   r[   Dictr   r^   r   r   r   r   r      N    
6	
Vr   c                   @   r   )AsyncVoiceGenerationClientr   c                C   r   r   r   r   r   r   r   r      r   z#AsyncVoiceGenerationClient.__init__Nr   r   r   c                   s  | j jjdtj| j   ddt|dur|dndtt	i | j 
 |dur0|di ni |durD|ddurD|dndd	|durO|d
nd	dI dH }d|j  kradk rkn ntt| S z| }W n ty   t|j|jdw t|j|d)a  
        Get possible parameters for the /v1/voice-generation/generate-voice endpoint.

        Parameters:
            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.voice_generation.generate_parameters()
        r    r!   r"   Nr#   r$   r%   r&   r   r'   r(   r-   r.   r/   r2   r?   r   r   r   rB      s@   	
z.AsyncVoiceGenerationClient.generate_parametersrC   rD   rE   rF   r>   c          
      C  s  | j jjdtj| j   ddt|dur|dnd|du s)|ddu r3t|||||dni t|||||dtt	|di tt	i | j 
 |durZ|di ni |durn|d	durn|d	nd
d|dury|dndd4 I dH M}d|j  krdk rn n| 2 z	3 dH W }|V  q6 	 W d  I dH  dS | I dH  z| }	W n ty   t|j|jdw t|j|	d1 I dH sw   Y  dS )a_  
        Generate a random voice based on parameters. This method returns a generated_voice_id in the response header, and a sample of the voice in the body. If you like the generated voice call /v1/voice-generation/create-voice with the generated_voice_id to create the voice.

        Parameters:
            - gender: Gender. Category code corresponding to the gender of the generated voice. Possible values: female, male.

            - accent: str. Category code corresponding to the accent of the generated voice. Possible values: american, british, african, australian, indian.

            - age: Age. Category code corresponding to the age of the generated voice. Possible values: young, middle_aged, old.

            - accent_strength: float. The strength of the accent of the generated voice. Has to be between 0.3 and 2.0.

            - text: str. Text to generate, text length has to be between 100 and 1000.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.voice_generation.generate(
            gender="male",
            accent="string",
            age="young",
            accent_strength=1.1,
            text="string",
        )
        rG   r!   rH   Nr#   rI   rJ   r$   r%   r&   r   r'   rK   r-   r.   r/   )r   r3   rL   r5   r6   r7   r8   r   r9   r   r:   r0   aiter_bytesareadr=   r   r   r>   rO   r   r   r   rQ     s`   '	
"z#AsyncVoiceGenerationClient.generaterR   rT   rU   rV   rS   c          	         s  |||d}|t ur||d< | jjjdtj| j  ddt|dur*|	dnd|du s7|	ddu r;t|ni t|tt
|	di tt
i | j |dur\|	d	i ni |durp|	d
durp|	d
ndd|dur{|	dnddI dH }d|j  krdk rn ntt| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)ao  
        Create a previously generated voice. This endpoint should be called after you fetched a generated_voice_id using /v1/voice-generation/generate-voice.

        Parameters:
            - voice_name: str. Name to use for the created voice.

            - voice_description: str. Description to use for the created voice.

            - generated_voice_id: str. The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.

            - labels: typing.Optional[typing.Dict[str, str]]. Optional, metadata to add to the created voice. Defaults to None.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.voice_generation.create_a_previously_generated_voice(
            voice_name="voice_name",
            voice_description="voice_description",
            generated_voice_id="generated_voice_id",
        )
        rW   rS   rG   r!   rX   Nr#   rI   r$   r%   r&   r   r'   rK   r-   r.   rY   r/   rZ   r\   r   r   r   r^   n  sZ   #	

z>AsyncVoiceGenerationClient.create_a_previously_generated_voice)r_   r`   ra   r   r   rb   rc   r	   r   rB   r   rd   r   re   AsyncIteratorrg   rQ   r[   rh   r   r^   r   r   r   r   rj      ri   rj   )%rb   urllib.parser5   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.jsonable_encoderr   core.remove_none_from_dictr   core.request_optionsr	   !errors.unprocessable_entity_errorr
   	types.ager   types.genderr   types.http_validation_errorr   types.voicer   )types.voice_generation_parameter_responser   pydantic.v1v1r;   ImportErrorcastAnyr[   r   rj   r   r   r   r   <module>   s.    Q