
    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  e j$                  e j&                  d      Z G d d      Z G d d      Zy)    N   )SyncClientWrapper   ),TextToSoundEffectsConvertRequestOutputFormat)RequestOptions)UnprocessableEntityError)HttpValidationError)construct_type)JSONDecodeError)ApiError)AsyncClientWrapper.c                       e Zd ZdefdZdeedddedej                  e	   dej                  e
   dej                  e
   d	ej                  e   d
ej                  e   fdZy)TextToSoundEffectsClientclient_wrapperc                    || _         y N_client_wrapperselfr   s     a/var/www/html/engine/venv/lib/python3.12/site-packages/elevenlabs/text_to_sound_effects/client.py__init__z!TextToSoundEffectsClient.__init__   
    -    Noutput_formatduration_secondsprompt_influencerequest_optionstextr   r   r   r   returnc             #     K   | j                   j                  j                  ddd|i|||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)uu  
        Turn text into sound effects for your videos, voice-overs or video games using the most advanced sound effects model in the world.

        Parameters
        ----------
        text : str
            The text that will get converted into a sound effect.

        output_format : typing.Optional[TextToSoundEffectsConvertRequestOutputFormat]
            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.

        duration_seconds : typing.Optional[float]
            The duration of the sound which will be generated in seconds. Must be at least 0.5 and at most 22. If set to None we will guess the optimal duration using the prompt. Defaults to None.

        prompt_influence : typing.Optional[float]
            A higher prompt influence makes your generation follow the prompt more closely while also making generations less variable. Must be a value between 0 and 1. Defaults to 0.3.

        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]
            The generated sound effect as an MP3 file

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.text_to_sound_effects.convert(
            text="Spacious braam suitable for high-impact movie trailer moments",
        )
        v1/sound-generationPOSTr   r    r   r   content-typeapplication/jsonmethodparamsjsonheadersr   omit   ,  N
chunk_size   r0     type_object_status_codebody)r   httpx_clientstreamOMITr8   get
iter_bytesreadr   typingcastr	   r
   r+   r   r   r    
r   r    r   r   r   r   	_response_chunk_size_chunk_response_jsons
             r   convertz TextToSoundEffectsClient.convert   sq    Z !!..55! $4$4  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G%	S %	Ss;   9EEA	D	EA/D?E+EEE	E)__name__
__module____qualname__r   r   r<   strr@   Optionalr   floatr   IteratorbytesrG    r   r   r   r      s    .*; . X\3737;?RS RS 'ST	RS
 !//%0RS !//%0RS  8RS 
	RSr   r   c                       e Zd ZdefdZdeedddedej                  e	   dej                  e
   dej                  e
   d	ej                  e   d
ej                  e   fdZy)AsyncTextToSoundEffectsClientr   c                    || _         y r   r   r   s     r   r   z&AsyncTextToSoundEffectsClient.__init__l   r   r   Nr   r    r   r   r   r   r!   c                 K   | j                   j                  j                  ddd|i|||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)u  
        Turn text into sound effects for your videos, voice-overs or video games using the most advanced sound effects model in the world.

        Parameters
        ----------
        text : str
            The text that will get converted into a sound effect.

        output_format : typing.Optional[TextToSoundEffectsConvertRequestOutputFormat]
            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.

        duration_seconds : typing.Optional[float]
            The duration of the sound which will be generated in seconds. Must be at least 0.5 and at most 22. If set to None we will guess the optimal duration using the prompt. Defaults to None.

        prompt_influence : typing.Optional[float]
            A higher prompt influence makes your generation follow the prompt more closely while also making generations less variable. Must be a value between 0 and 1. Defaults to 0.3.

        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]
            The generated sound effect as an MP3 file

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.text_to_sound_effects.convert(
                text="Spacious braam suitable for high-impact movie trailer moments",
            )


        asyncio.run(main())
        r#   r$   r   r%   r&   r'   r(   Nr.   r/   r0   r1   r2   r3   r4   r7   )r   r:   r;   r<   r8   r=   aiter_bytesareadr   r@   rA   r	   r
   r+   r   r   r    rB   s
             r   rG   z%AsyncTextToSoundEffectsClient.converto   s    j ''44;;! $4$4  2 , < 
 %	S %	S  W)//5#5M\Mh/"5"5lD"InrK(1(=(=(=(U % %f$oo'''((C/2/*&9(1(8  "+!1 y'<'<>RRK%	S(%(U-%	S %	S %	S. ( # W9+@+@y~~VVWG%	S %	S %	Ss   =E?D" E?E*A D<D&	D$
D&D<'D:(A#D<E*"E?$D&&D<(E?3D64E?:D<<+E''E**E<0E31E<8E?)rH   rI   rJ   r   r   r<   rK   r@   rL   r   rM   r   AsyncIteratorrO   rG   rP   r   r   rR   rR   k   s    .*< . X\3737;?ZS ZS 'ST	ZS
 !//%0ZS !//%0ZS  8ZS 
		e	$ZSr   rR   )r@   core.client_wrapperr   9types.text_to_sound_effects_convert_request_output_formatr   core.request_optionsr   !errors.unprocessable_entity_errorr   types.http_validation_errorr	   core.unchecked_base_modelr
   json.decoderr   core.api_errorr   r   rA   Anyr<   r   rR   rP   r   r   <module>ra      sZ     3 s 1 H = 6 ( % 4 v{{6::s#VS VSr^S ^Sr   