
    >|h/R              
       P   d dl Z d dlZd dlZd dlZd dlZd dl mZmZmZmZmZ ddl	m
Z
mZ ddlmZmZ ddlmZmZmZmZ ddlmZ ddlmZ dd	lmZ  ed
d edddd            ZeZeZeZdedefdZ e j@                  e jB                  d      Z" G d de
      Z# G d de      Z$y)    N)IteratorOptionalUnionr   AsyncIterator   )BaseElevenLabsAsyncBaseElevenLabs)RequestOptionsApiError)VoiceVoiceSettings%PronunciationDictionaryVersionLocatorModel)ElevenLabsEnvironment)RealtimeTextToSpeechClient)OutputFormatEXAVITQu4vr4xnSDxMaLSarahgQ?g      ?g        T)	stabilitysimilarity_booststyleuse_speaker_boost)voice_idnamesettingsvalreturnc                 @    t        t        j                  d|             S )Nz^[a-zA-Z0-9]{20}$)boolrematch)r   s    P/var/www/html/test/engine/venv/lib/python3.12/site-packages/elevenlabs/client.pyis_voice_idr#   #   s    -s344    .c                   v    e Zd ZdZdej
                   ej                  d      ddddej                  e
   dedej                  e
   d	ej                  e   d
ej                  ej                     f
 fdZ	 	 d!de
dej                  e
   de
dej                  e
   dej                  e   defdZeej(                  ddddedddee
ee
   f   deeeef   dej                  e   deeef   dej                  e   dede	e   dej                  ej@                  e!      dej                  e   dee"   fd Z# xZ$S )"
ElevenLabsa  
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propogate to these functions.

    Parameters:
        - base_url: typing.Optional[str]. The base url to use for requests from the client.

        - environment: ElevenLabsEnvironment. The environment to use for requests from the client. from .environment import ElevenLabsEnvironment

                                              Defaults to ElevenLabsEnvironment.PRODUCTION

        - api_key: typing.Optional[str].

        - timeout: typing.Optional[float]. The timeout to be used, in seconds, for requests by default the timeout is 60 seconds.

        - httpx_client: typing.Optional[httpx.Client]. The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
    ---
    from elevenlabs.client import ElevenLabs

    client = ElevenLabs(
        api_key="YOUR_API_KEY",
    )
    NELEVENLABS_API_KEY<   base_urlenvironmentapi_keytimeouthttpx_clientr*   r+   r,   r-   r.   c                d    t         |   |||||       t        | j                        | _        y )Nr)   )client_wrapper)super__init__r   _client_wrappertext_to_speech)selfr*   r+   r,   r-   r.   	__class__s         r"   r2   zElevenLabs.__init__B   s;     	#% 	 	
 9H\H\]r$   r   filesdescriptionlabelsrequest_optionsr   c                    | j                   j                  |||D cg c]  }t        |d       c}t        t	        j
                  |xs i                   }| j                   j                  |j                  |      S c c}w )a  
          This is a manually maintained helper function that clones a voice from a set of audio files.
          **NOTE**: This function is a helper function and is simply making 
          calls to the `add` and `get` functions of the `voices` endpoint.

          Parameters:
              - name: str. The name that identifies this voice. This will be displayed in the dropdown of the website.

              - files: typing.List[str]. The filepaths of the audio files to be used to create the voice.

              - description: str. How would you describe the voice?

              - labels: str. Serialized labels dictionary for the voice.

              - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        rbr   r8   r7   r9   r:   voicesaddopenstrjsondumpsgetr   r5   r   r7   r8   r9   r:   fileadd_voice_responses           r"   clonezElevenLabs.cloneT   sy    0 "[[__!.34ddD!4TZZ"-.	 - 
 {{

%
%)  
 	
 5s   A?eleven_multilingual_v2r   Fmp3_44100_128voicevoice_settingsmodeloptimize_streaming_latencystreamoutput_format!pronunciation_dictionary_locatorsr:   textrN   rO   rP   rQ   rR   rS   rT   c       	   
      r   t        t              rt              r}
nt        t              rQ| j                  j	                  |	d      }t        fd|j                  D        d      }|t        d d      |}
nXt        t              r8j                  }
|t        j                  k(  r)j                  j                  }nt        j                  }
t        |t              r|}nt        |t              r|j                  }|rpt        |t              r#| j                  j                  |
|||||	|      S t        |t              r!| j                  j!                  |
||||		      S t        d
      t        |t              st        d      | j                  j#                  |
|||||	|      S )uX  
            - text: Union[str, Iterator[str]]. The string or stream of strings that will get converted into speech.

            - voice: str. A voice id, name, or voice response. Defaults to the Sarah voice. 

            - model: typing.Optional[str]. Identifier of the model that will be used, you can query them using GET /v1/models. 
                                           The model needs to have support for text to speech, you can check this using the 
                                           can_do_text_to_speech property.                                                                

            - optimize_streaming_latency: typing.Optional[int]. You can turn on latency optimizations at some cost of quality. The best possible final latency varies by model. Possible values:
                                                                0 - default mode (no latency optimizations)
                                                                1 - normal latency optimizations (about 50% of possible latency improvement of option 3)
                                                                2 - strong latency optimizations (about 75% of possible latency improvement of option 3)
                                                                3 - max latency optimizations
                                                                4 - max latency optimizations, but also with text normalizer turned off for even more latency savings (best latency, but can mispronounce eg numbers and dates).

                                                                Defaults to 0.
            
            - stream: bool. If true, the function will return a generator that will yield the audio in chunks.    

                            Defaults to False.                                                                

            - output_format: typing.Optional[OutputFormat]. Output format of the generated audio. Must be one of:
                                                   mp3_22050_32 - output format, mp3 with 22.05kHz sample rate at 32kbps.
                                                   mp3_44100_32 - output format, mp3 with 44.1kHz sample rate at 32kbps.
                                                   mp3_44100_64 - output format, mp3 with 44.1kHz sample rate at 64kbps.
                                                   mp3_44100_96 - output format, mp3 with 44.1kHz sample rate at 96kbps.
                                                   mp3_44100_128 - default output format, mp3 with 44.1kHz sample rate at 128kbps.
                                                   mp3_44100_192 - output format, mp3 with 44.1kHz sample rate at 192kbps. Requires you to be subscribed to Creator tier or above.
                                                   pcm_16000 - PCM format (S16LE) with 16kHz sample rate.
                                                   pcm_22050 - PCM format (S16LE) with 22.05kHz sample rate.
                                                   pcm_24000 - PCM format (S16LE) with 24kHz sample rate.
                                                   pcm_44100 - PCM format (S16LE) with 44.1kHz sample rate. Requires you to be subscribed to Independent Publisher tier or above.
                                                   ulaw_8000 - μ-law format (sometimes written mu-law, often approximated as u-law) with 8kHz sample rate. Note that this format is commonly used for Twilio audio inputs.

                                                    Defaults to mp3_44100_128.
            
            - voice_settings: typing.Optional[VoiceSettings]. Voice settings overriding stored setttings for the given voice. They are applied only on the given request.

            - pronunciation_dictionary_locators: typing.Optional[typing.Sequence[PronunciationDictionaryVersionLocator]]. A list of pronunciation dictionary locators (id, version_id) to be applied to the text. They will be applied in order. You may have up to 3 locators per request                                                    

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        Tr:   show_legacyc              3   V   K   | ]   }|j                   k(  s|j                   " y wNr   r   .0vrN   s     r"   	<genexpr>z&ElevenLabs.generate.<locals>.<genexpr>   $     "a!QRQWQW[`Q`1::"a   ))NVoice  not found.body)r   rO   rQ   rS   rU   r:   rT   model_id)r   rO   rS   rU   r:   rf   z)Text is neither a string nor an iterator.+Text must be a string when stream is False.r   rf   rO   rQ   rS   rU   r:   rT   )
isinstancerC   r#   r@   get_allnextr   r   r   DEFAULT_VOICEr   r   rf   r4   convert_as_streamr   convert_realtimeconvertr5   rU   rN   rO   rP   rQ   rR   rS   rT   r:   r   voices_responsemaybe_voice_idrf   s     `           r"   generatezElevenLabs.generatew   s   t eS!k%&8Hs#"kk11/_c1dO!"a7M7M"acghN%fUG;$?@@%Hu%~~H!7!772!&$--HeS!Hu%~~H $$**<<%#1/I"/$36W% = 	 	 D(+**;;%#1"/$3% <   $OPPdC($QRR&&..!!-+E+ /2S / 	 	r$   )NN)%__name__
__module____qualname____doc__r   
PRODUCTIONosgetenvtypingr   rC   floathttpxClientr2   Listr
   r   rJ   rl   r   OMITr   r   VoiceId	VoiceNamer   ModelIdr   intr   r   Sequencer   bytesrs   __classcell__)r6   s   @r"   r&   r&   +   s   2 *.-B-M-M(1		2F(G*,6:^ //#&^ +	^
 %^ '^ ooell3^. &*9=!
!
 [[!
 	!

 ooc"!
 ~6!
 
!
N 1>7D7M7M%=9:.= 9=s #x}$%s 7Iu,-	s
 oom4s 7E>"s #)//#"6s s l+s *0OOAB*
s ~6s 
%sr$   r&   c                   d   e Zd ZdZ	 ddedej                  e   dededej                  e   de	fd	Z
eej                  d
dddedddedeeee	f   dej                  e   deeef   dej                  e   dedee   dej                  ej.                  e      dej                  e   dee   fdZy)AsyncElevenLabsa(  
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propogate to these functions.

    Parameters:
        - base_url: typing.Optional[str]. The base url to use for requests from the client.

        - environment: ElevenLabsEnvironment. The environment to use for requests from the client. from .environment import ElevenLabsEnvironment

                                              Defaults to ElevenLabsEnvironment.PRODUCTION

        - api_key: typing.Optional[str].

        - timeout: typing.Optional[float]. The timeout to be used, in seconds, for requests by default the timeout is 60 seconds.

        - httpx_client: typing.Optional[httpx.AsyncClient]. The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
    ---
    from elevenlabs.client import AsyncElevenLabs

    client = AsyncElevenLabs(
        api_key="YOUR_API_KEY",
    )
    Nr   r7   r8   r9   r:   r   c                 8  K   | j                   j                  |||D cg c]  }t        |d       c}t        t	        j
                  |xs i                    d{   }| j                   j                  |j                  |       d{   S c c}w 7 87 w)a  
          This is a manually mnaintained helper function that generates a 
          voice from provided text.

          **NOTE**: This function is a helper function and is simply making 
          calls to the `text_to_speech.convert` and`text_to_speech.convert_as_stream`
          functions.

          Parameters:
              - name: str. The name that identifies this voice. This will be displayed in the dropdown of the website.

              - files: typing.List[str]. The filepaths of the audio files to be used to create the voice.

              - description: str. How would you describe the voice?

              - labels: str. Serialized labels dictionary for the voice.

              - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        r<   r=   Nr>   r?   rG   s           r"   rJ   zAsyncElevenLabs.clone  s     6 $(;;??!.34ddD!4TZZ"-.	 $3 $
 
 [[__

%
%) % 
 
 	
 5

s-   BB,BB.BB
BBrK   r   FrL   rM   rU   rN   rO   rP   rQ   rR   rS   rT   c       	   
        K   t        t              rt              r}
nt        t              rY| j                  j	                  |	d       d{   }t        fd|j                  D        d      }|st        d d      |}
nXt        t              r8j                  }
|t        j                  k(  r)j                  j                  }nt        j                  }
t        |t              r|}nt        |t              r|j                  }|r#| j                  j                  |
|||||	|      S t        |t              st        d	      | j                  j                  |
|||||	|      S 7 $w)
u  
          This is a manually mnaintained helper function that generates a 
          voice from provided text.

          **NOTE**: This function is a helper function and is simply making 
          calls to the `text_to_speech.convert` and`text_to_speech.convert_as_stream`
          functions.

            - text: str. The string that will get converted into speech. The Async client does not support streaming.

            - voice: str. A voice id, name, or voice response. Defaults to the Rachel voice. 

            - model: typing.Optional[str]. Identifier of the model that will be used, you can query them using GET /v1/models. 
                                           The model needs to have support for text to speech, you can check this using the 
                                           can_do_text_to_speech property.                                                                

            - optimize_streaming_latency: typing.Optional[int]. You can turn on latency optimizations at some cost of quality. The best possible final latency varies by model. Possible values:
                                                                0 - default mode (no latency optimizations)
                                                                1 - normal latency optimizations (about 50% of possible latency improvement of option 3)
                                                                2 - strong latency optimizations (about 75% of possible latency improvement of option 3)
                                                                3 - max latency optimizations
                                                                4 - max latency optimizations, but also with text normalizer turned off for even more latency savings (best latency, but can mispronounce eg numbers and dates).

                                                                Defaults to 0.
            
            - stream: bool. If true, the function will return a generator that will yield the audio in chunks.    

                            Defaults to False.                                                                

            - output_format: typing.Optional[OutputFormat]. Output format of the generated audio. Must be one of:
                                                   mp3_22050_32 - output format, mp3 with 22.05kHz sample rate at 32kbps.
                                                   mp3_44100_32 - output format, mp3 with 44.1kHz sample rate at 32kbps.
                                                   mp3_44100_64 - output format, mp3 with 44.1kHz sample rate at 64kbps.
                                                   mp3_44100_96 - output format, mp3 with 44.1kHz sample rate at 96kbps.
                                                   mp3_44100_128 - default output format, mp3 with 44.1kHz sample rate at 128kbps.
                                                   mp3_44100_192 - output format, mp3 with 44.1kHz sample rate at 192kbps. Requires you to be subscribed to Creator tier or above.
                                                   pcm_16000 - PCM format (S16LE) with 16kHz sample rate.
                                                   pcm_22050 - PCM format (S16LE) with 22.05kHz sample rate.
                                                   pcm_24000 - PCM format (S16LE) with 24kHz sample rate.
                                                   pcm_44100 - PCM format (S16LE) with 44.1kHz sample rate. Requires you to be subscribed to Independent Publisher tier or above.
                                                   ulaw_8000 - μ-law format (sometimes written mu-law, often approximated as u-law) with 8kHz sample rate. Note that this format is commonly used for Twilio audio inputs.

                                                    Defaults to mp3_44100_128.
            
            - voice_settings: typing.Optional[VoiceSettings]. Voice settings overriding stored setttings for the given voice. They are applied only on the given request.

            - pronunciation_dictionary_locators: typing.Optional[typing.Sequence[PronunciationDictionaryVersionLocator]]. A list of pronunciation dictionary locators (id, version_id) to be applied to the text. They will be applied in order. You may have up to 3 locators per request                                                    

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        TrW   Nc              3   V   K   | ]   }|j                   k(  s|j                   " y wrZ   r[   r\   s     r"   r_   z+AsyncElevenLabs.generate.<locals>.<genexpr>p  r`   ra   rb   rc   rd   rh   rg   )ri   rC   r#   r@   rj   rk   r   r   r   rl   r   r   rf   r4   rm   ro   rp   s     `           r"   rs   zAsyncElevenLabs.generate+  sk    B eS!k%&8Hs#$(KK$7$7ei$7$jjO!"a7M7M"acghN!fUG;$?@@%Hu%~~H!7!772!&$--HeS!Hu%~~H&&88!!-+E+ /2S 9 	 	 dC($QRR&&..!!-+E+ /2S / 	 	A ks   AE9E6D$E9rZ   )rt   ru   rv   rw   rC   r{   r   r   r
   r   rJ   rl   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rs    r$   r"   r   r      sD   : :>$
$
 [[$
 	$

 $
 ~6$
 
$
T 1>7D7M7M%=9:.= 9=m m 7Iu,-	m
 oom4m 7E>"m #)//#"6m m l+m *0OOAB*
m ~6m 
u	mr$   r   )%r{   rD   r    ry   r}   r   r   r   r   base_clientr   r	   corer
   r   typesr   r   r   r   r+   r   realtime_ttsr   r   rl   rC   r   r   r   r   r#   castAnyr   r&   r   r   r$   r"   <module>r      s      	 	  & */ / . 4  #	C4 	
5S 5T 5
 v{{6::s# Dk) kr$   