
    >|h;H                         d dl 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 j0                  e j2                  d      Z G d d      Z G d d      Zy)    N   )SyncClientWrapper)RequestOptions) VoiceGenerationParameterResponse)construct_type)JSONDecodeError)ApiError)Gender)Age)UnprocessableEntityError)HttpValidationError)Voice)AsyncClientWrapper.c                   Z   e Zd ZdefdZdddej                  e   defdZ	ddde
d	ed
edededej                  e   dej                  e   fdZeedddedededej                  ej$                  e      dej                  ej&                  eef      dej                  e   defdZy)VoiceGenerationClientclient_wrapperc                    || _         y N_client_wrapperselfr   s     a/var/www/html/test/engine/venv/lib/python3.12/site-packages/elevenlabs/voice_generation/client.py__init__zVoiceGenerationClient.__init__   
    -    Nrequest_optionsr   returnc                   | j                   j                  j                  dd|      }	 d|j                  cxk  rdk  r:n n7t	        j
                  t        t        t        |j                                     S |j                         }t        |j                  |      # t        $ r" t        |j                  |j                        w xY w)a%  
        Get possible parameters for the /v1/voice-generation/generate-voice endpoint.

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

        Returns
        -------
        VoiceGenerationParameterResponse
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.voice_generation.generate_parameters()
        -v1/voice-generation/generate-voice/parametersGETmethodr      ,  type_object_status_codebodyr   httpx_clientrequestr+   typingcastr   r   jsonr   r	   textr   r   	_response_response_jsons       r   generate_parametersz)VoiceGenerationClient.generate_parameters   s    2 ((55==;+ > 
	
	Si++1c1{{4"> ) 0  '^^-N 9#8#8~NN  	Sy'<'<9>>RR	Ss   AB  9B   +Cgenderaccentageaccent_strengthr3   c             #     K   | j                   j                  j                  dd|||||dddi|t              5 }	 d|j                  cxk  rdk  r>n n;||j                  d
d      nd}|j                  |      D ]  }	|	  	 d	d	d	       y	|j                          |j                  dk(  r@t        t        j                  t        t        t        |j                                           |j                         }
t        |j                  |
      # t        $ r" t        |j                  |j                         w xY w# 1 sw Y   y	xY ww)u  
        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: british, american, 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. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Yields
        ------
        typing.Iterator[bytes]
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.voice_generation.generate(
            gender="female",
            accent="american",
            age="middle_aged",
            accent_strength=2.0,
            text="It sure does, Jackie… My mama always said: “In Carolina, the air's so thick you can wear it!”",
        )
        "v1/voice-generation/generate-voicePOSTr8   r9   r:   r;   r3   content-typeapplication/jsonr$   r2   headersr   omitr%   r&   N
chunk_size   rE     r'   r*   )r   r.   streamOMITr+   get
iter_bytesreadr   r0   r1   r   r   r2   r   r	   r3   r   r8   r9   r:   r;   r3   r   r5   _chunk_size_chunkr6   s              r   generatezVoiceGenerationClient.generateE   sk    j !!..550  #2  2 , 6 
 $	S W)//5#5M\Mh/"5"5lD"InrK"+"6"6+"6"N %$%+$	S $	S,  ((C/2/*&9(1(8  "+!1 y'<'<>RR # W9+@+@y~~VVWE$	S $	Ss;   8EEA	D	EA/D>E+E  EEEplayed_not_selected_voice_idslabelsr   
voice_namevoice_descriptiongenerated_voice_idrS   rT   c          
      X   | j                   j                  j                  dd|||||dddi|t              }	 d|j                  cxk  rdk  r:n n7t        j                  t        t        t        |j                         	            S |j                  d
k(  r@t        t        j                  t        t        t        |j                         	                  |j                         }t        |j                  |      # t        $ r" t        |j                  |j                        w xY w)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/text-to-voice/create-previews and fetch the generated_voice_id from the response header if don't have one yet.

        played_not_selected_voice_ids : typing.Optional[typing.Sequence[str]]
            List of voice ids that the user has played but not selected. Used for RLHF.

        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.

        Returns
        -------
        Voice
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.voice_generation.create_a_previously_generated_voice(
            voice_name="Alex",
            voice_description="Middle-aged American woman",
            generated_voice_id="rbVJFu6SGRD1dbWpKnWl",
        )
         v1/voice-generation/create-voicer>   rU   rV   rW   rS   rT   r@   rA   rB   r%   r&   r'   rH   r*   r   r.   r/   rJ   r+   r0   r1   r   r   r2   r   r   r   r	   r3   	r   rU   rV   rW   rS   rT   r   r5   r6   s	            r   #create_a_previously_generated_voicez9VoiceGenerationClient.create_a_previously_generated_voice   s%   f ((55==.(%6&81N   2 , > 
	 	Si++1c1{{"# ) 0  $$+.KK+&"5$-NN$4  '^^-N 9#8#8~NN  	Sy'<'<9>>RR	Ss   AC> AC> >+D))__name__
__module____qualname__r   r   r0   Optionalr   r   r7   r
   strr   floatIteratorbytesrQ   rJ   SequenceDictr   r]    r   r   r   r      sE   .*; . EI*O"(//."A*O	)*Oh <@YS YS 	YS
 YS YS YS  8YS 
	YSB PT9=;?YO YO 	YO
  YO (.vs7K'LYO CH 56YO  8YO 
YOr   r   c                   Z   e Zd ZdefdZdddej                  e   defdZ	ddde
d	ed
edededej                  e   dej                  e   fdZeedddedededej                  ej$                  e      dej                  ej&                  eef      dej                  e   defdZy)AsyncVoiceGenerationClientr   c                    || _         y r   r   r   s     r   r   z#AsyncVoiceGenerationClient.__init__   r   r   Nr   r   r   c                  K   | j                   j                  j                  dd|       d{   }	 d|j                  cxk  rdk  r:n n7t	        j
                  t        t        t        |j                                     S |j                         }t        |j                  |      7 {# t        $ r" t        |j                  |j                        w xY ww)	a  
        Get possible parameters for the /v1/voice-generation/generate-voice endpoint.

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

        Returns
        -------
        VoiceGenerationParameterResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.voice_generation.generate_parameters()


        asyncio.run(main())
        r!   r"   r#   Nr%   r&   r'   r*   r-   r4   s       r   r7   z.AsyncVoiceGenerationClient.generate_parameters   s     B ..;;CC;+ D 
 
	
	Si++1c1{{4"> ) 0  '^^-N 9#8#8~NN#
  	Sy'<'<9>>RR	Ss3   ,CB*CAB, CB, C,+CCr8   r9   r:   r;   r3   c                  K   | j                   j                  j                  dd|||||dddi|t              4 d{   }	 d|j                  cxk  rd	k  r:n n7||j                  d
d      nd}|j                  |      2 3 d{   }	|	 |j                          d{    |j                  dk(  r@t        t        j                  t        t        t        |j                                           |j                         }
t        |j                  |
      7 7 6 	 ddd      d{  7   y7 # t        $ r" t        |j                  |j                         w xY w# 1 d{  7  sw Y   yxY ww)uI  
        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: british, american, 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. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Yields
        ------
        typing.AsyncIterator[bytes]
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.voice_generation.generate(
                gender="female",
                accent="american",
                age="middle_aged",
                accent_strength=2.0,
                text="It sure does, Jackie… My mama always said: “In Carolina, the air's so thick you can wear it!”",
            )


        asyncio.run(main())
        r=   r>   r?   r@   rA   rB   Nr%   r&   rE   rF   rG   rH   r'   r*   )r   r.   rI   rJ   r+   rK   aiter_bytesareadr   r0   r1   r   r   r2   r   r	   r3   rN   s              r   rQ   z#AsyncVoiceGenerationClient.generate4  s    z ''44;;0  #2  2 , < 
 $	S $	S W)//5#5M\Mh/"5"5lD"InrK(1(=(=(=(U % %f$oo'''((C/2/*&9(1(8  "+!1 y'<'<>RRI$	S&%(U+$	S $	S $	S, ( # W9+@+@y~~VVWE$	S $	S $	Ss   <E>D!E>E)A D;D%D#	D%D;&D9'A#D;
E)!E>#D%%D;'E>2D53E>9D;;+E&&E))E;/E20E;7E>rR   rU   rV   rW   rS   rT   c          
      t  K   | j                   j                  j                  dd|||||dddi|t               d{   }	 d|j                  cxk  rd	k  r:n n7t        j                  t        t        t        |j                         
            S |j                  dk(  r@t        t        j                  t        t        t        |j                         
                  |j                         }t        |j                  |      7 # t        $ r" t        |j                  |j                        w xY ww)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/text-to-voice/create-previews and fetch the generated_voice_id from the response header if don't have one yet.

        played_not_selected_voice_ids : typing.Optional[typing.Sequence[str]]
            List of voice ids that the user has played but not selected. Used for RLHF.

        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.

        Returns
        -------
        Voice
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.voice_generation.create_a_previously_generated_voice(
                voice_name="Alex",
                voice_description="Middle-aged American woman",
                generated_voice_id="rbVJFu6SGRD1dbWpKnWl",
            )


        asyncio.run(main())
        rY   r>   rZ   r@   rA   rB   Nr%   r&   r'   rH   r*   r[   r\   s	            r   r]   z>AsyncVoiceGenerationClient.create_a_previously_generated_voice  s5    v ..;;CC.(%6&81N   2 , D 
 
	 	Si++1c1{{"# ) 0  $$+.KK+&"5$-NN$4  '^^-N 9#8#8~NNM
H  	Sy'<'<9>>RR	Ss5   ;D8DD8AD
 D8AD
 1D8
+D55D8)r^   r_   r`   r   r   r0   ra   r   r   r7   r
   rb   r   rc   AsyncIteratorre   rQ   rJ   rf   rg   r   r]   rh   r   r   rj   rj      sG   .*< . EI2O"(//."A2O	)2Ox <@aS aS 	aS
 aS aS aS  8aS 
		e	$aSR PT9=;?aO aO 	aO
  aO (.vs7K'LaO CH 56aO  8aO 
aOr   rj   )r0   core.client_wrapperr   core.request_optionsr   )types.voice_generation_parameter_responser   core.unchecked_base_modelr   json.decoderr   core.api_errorr	   types.genderr
   	types.ager   !errors.unprocessable_entity_errorr   types.http_validation_errorr   types.voicer   r   r1   AnyrJ   r   rj   rh   r   r   <module>r~      sc     3 1 X 6 ( % !  H =  4 v{{6::s#dO dON|O |Or   