
    >|hF                         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  e j,                  e j.                  d      Z G d d      Z G d d      Zy)    N   )SyncClientWrapper   ),TextToVoiceCreatePreviewsRequestOutputFormat)RequestOptions)VoicePreviewsResponseModel)construct_type)UnprocessableEntityError)HttpValidationError)JSONDecodeError)ApiError)Voice)AsyncClientWrapper.c                      e Zd ZdefdZdeeeeedddededej                  e	   dej                  e
   d	ej                  e   d
ej                  e   dej                  e   dej                  e   dej                  e   defdZeedddedededej                  ej                   eef      dej                  ej"                  e      dej                  e   defdZy)TextToVoiceClientclient_wrapperc                    || _         y N_client_wrapperselfr   s     ^/var/www/html/test/engine/venv/lib/python3.12/site-packages/elevenlabs/text_to_voice/client.py__init__zTextToVoiceClient.__init__   
    -    Noutput_formatauto_generate_textloudnessqualityseedguidance_scalerequest_optionsvoice_descriptiontextr   r   r    r!   r"   r#   r$   returnc       	         b   | j                   j                  j                  ddd|i|||||||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)ut
  
        Generate a custom voice based on voice description. This method returns a list of voice previews. Each preview has a generated_voice_id and a sample of the voice as base64 encoded mp3 audio. If you like the a voice previewand want to create the voice call /v1/text-to-voice/create-voice-from-preview with the generated_voice_id to create the voice.

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

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

        output_format : typing.Optional[TextToVoiceCreatePreviewsRequestOutputFormat]
            Output format of the generated audio. Formatted as codec_sample_rate_bitrate. So an mp3 with 22.05kHz sample rate at 32kbs is represented as mp3_22050_32. MP3 with 192kbps bitrate requires you to be subscribed to Creator tier or above. PCM with 44.1kHz sample rate requires you to be subscribed to Pro tier or above. Note that the μ-law format (sometimes written mu-law, often approximated as u-law) is commonly used for Twilio audio inputs.

        auto_generate_text : typing.Optional[bool]
            Whether to automatically generate a text suitable for the voice description.

        loudness : typing.Optional[float]
            Controls the volume level of the generated voice. -1 is quietest, 1 is loudest, 0 corresponds to roughly -24 LUFS.

        quality : typing.Optional[float]
            Higher quality results in better voice output but less variety.

        seed : typing.Optional[int]
            Random number that controls the voice generation. Same seed with same inputs produces same voice.

        guidance_scale : typing.Optional[float]
            Controls how closely the AI follows the prompt. Lower numbers give the AI more freedom to be creative, while higher numbers force it to stick more to the prompt. High numbers can cause voice to sound artificial or robotic. We recommend to use longer, more detailed prompts at lower Guidance Scale.

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

        Returns
        -------
        VoicePreviewsResponseModel
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.text_to_voice.create_previews(
            voice_description="A sassy squeaky mouse",
            text="Every act of kindness, no matter how small, carries value and can make a difference, as no gesture of goodwill is ever wasted.",
        )
         v1/text-to-voice/create-previewsPOSTr   r%   r&   r   r    r!   r"   r#   content-typeapplication/jsonmethodparamsjsonheadersr$   omit   ,  type_object_  status_codebodyr   httpx_clientrequestOMITr;   typingcastr   r	   r1   r
   r   r   r   r&   r   r%   r&   r   r   r    r!   r"   r#   r$   	_response_response_jsons               r   create_previewsz!TextToVoiceClient.create_previews   s7   | ((55==. &7&8$""0  2 ,' > 
	*	Si++1c1{{."8 ) 0  $$+.KK+&"5$-NN$4  '^^-N 9#8#8~NN  	Sy'<'<9>>RR	Ss   AD AD +D.labelsplayed_not_selected_voice_idsr$   
voice_namegenerated_voice_idrH   rI   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 voice from previously generated voice preview. This endpoint should be called after you fetched a generated_voice_id using POST /v1/text-to-voice/create-previews.

        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.

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

        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.

        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.text_to_voice.create_voice_from_preview(
            voice_name="Sassy squeaky mouse",
            voice_description="A sassy squeaky mouse",
            generated_voice_id="37HceQefKmEi3bGovXjL",
        )
        *v1/text-to-voice/create-voice-from-previewr*   rJ   r%   rK   rH   rI   r,   r-   r/   r1   r2   r$   r3   r4   r5   r6   r9   r:   r   r>   r?   r@   r;   rA   rB   r   r	   r1   r
   r   r   r   r&   	r   rJ   r%   rK   rH   rI   r$   rD   rE   s	            r   create_voice_from_previewz+TextToVoiceClient.create_voice_from_preview   s%   f ((55==8(%6&8 1N  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   r@   strrA   Optionalr   boolfloatintr   r   rF   DictSequencer   rR    r   r   r   r      s   .*; . X\48+/*.%)15;?iO iO 	iO
 'STiO #OOD1iO //%(iO 'iO ooc"iO .iO  8iO 
$iOb :>OS;?YO YO 	YO
  YO CH 56YO (.vs7K'LYO  8YO 
YOr   r   c                      e Zd ZdefdZdeeeeedddededej                  e	   dej                  e
   d	ej                  e   d
ej                  e   dej                  e   dej                  e   dej                  e   defdZeedddedededej                  ej                   eef      dej                  ej"                  e      dej                  e   defdZy)AsyncTextToVoiceClientr   c                    || _         y r   r   r   s     r   r   zAsyncTextToVoiceClient.__init__   r   r   Nr   r%   r&   r   r   r    r!   r"   r#   r$   r'   c       	         ~  K   | j                   j                  j                  ddd|i|||||||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)u
  
        Generate a custom voice based on voice description. This method returns a list of voice previews. Each preview has a generated_voice_id and a sample of the voice as base64 encoded mp3 audio. If you like the a voice previewand want to create the voice call /v1/text-to-voice/create-voice-from-preview with the generated_voice_id to create the voice.

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

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

        output_format : typing.Optional[TextToVoiceCreatePreviewsRequestOutputFormat]
            Output format of the generated audio. Formatted as codec_sample_rate_bitrate. So an mp3 with 22.05kHz sample rate at 32kbs is represented as mp3_22050_32. MP3 with 192kbps bitrate requires you to be subscribed to Creator tier or above. PCM with 44.1kHz sample rate requires you to be subscribed to Pro tier or above. Note that the μ-law format (sometimes written mu-law, often approximated as u-law) is commonly used for Twilio audio inputs.

        auto_generate_text : typing.Optional[bool]
            Whether to automatically generate a text suitable for the voice description.

        loudness : typing.Optional[float]
            Controls the volume level of the generated voice. -1 is quietest, 1 is loudest, 0 corresponds to roughly -24 LUFS.

        quality : typing.Optional[float]
            Higher quality results in better voice output but less variety.

        seed : typing.Optional[int]
            Random number that controls the voice generation. Same seed with same inputs produces same voice.

        guidance_scale : typing.Optional[float]
            Controls how closely the AI follows the prompt. Lower numbers give the AI more freedom to be creative, while higher numbers force it to stick more to the prompt. High numbers can cause voice to sound artificial or robotic. We recommend to use longer, more detailed prompts at lower Guidance Scale.

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

        Returns
        -------
        VoicePreviewsResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.text_to_voice.create_previews(
                voice_description="A sassy squeaky mouse",
                text="Every act of kindness, no matter how small, carries value and can make a difference, as no gesture of goodwill is ever wasted.",
            )


        asyncio.run(main())
        r)   r*   r   r+   r,   r-   r.   Nr4   r5   r6   r9   r:   r=   rC   s               r   rF   z&AsyncTextToVoiceClient.create_previews   sG    L ..;;CC. &7&8$""0  2 ,' D 
 
	*	Si++1c1{{."8 ) 0  $$+.KK+&"5$-NN$4  '^^-N 9#8#8~NNW
R  	Sy'<'<9>>RR	Ss8   A D=DD=AD D=AD 6D=+D::D=rG   rJ   rK   rH   rI   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 voice from previously generated voice preview. This endpoint should be called after you fetched a generated_voice_id using POST /v1/text-to-voice/create-previews.

        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.

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

        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.

        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.text_to_voice.create_voice_from_preview(
                voice_name="Sassy squeaky mouse",
                voice_description="A sassy squeaky mouse",
                generated_voice_id="37HceQefKmEi3bGovXjL",
            )


        asyncio.run(main())
        rM   r*   rN   r,   r-   rO   Nr4   r5   r6   r9   r:   rP   rQ   s	            r   rR   z0AsyncTextToVoiceClient.create_voice_from_previewV  s5    v ..;;CC8(%6&8 1N  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)rS   rT   rU   r   r   r@   rV   rA   rW   r   rX   rY   rZ   r   r   rF   r[   r\   r   rR   r]   r   r   r_   r_      s   .*< . X\48+/*.%)15;?qO qO 	qO
 'STqO #OOD1qO //%(qO 'qO ooc"qO .qO  8qO 
$qOr :>OS;?aO aO 	aO
  aO CH 56aO (.vs7K'LaO  8aO 
aOr   r_   )rA   core.client_wrapperr   9types.text_to_voice_create_previews_request_output_formatr   core.request_optionsr   #types.voice_previews_response_modelr   core.unchecked_base_modelr	   !errors.unprocessable_entity_errorr
   types.http_validation_errorr   json.decoderr   core.api_errorr   types.voicer   r   rB   Anyr@   r   r_   r]   r   r   <module>rn      s`     3 s 1 L 6 H = ( %  4 v{{6::s#HO HOVXO XOr   