
    jU              
          d dl Z 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 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"dedefdZ# e jH                  e jJ                  d      Z&d Z'd Z( G d de      Z) G d de      Z*y)    Nwraps)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    /home/cube/projects/richard/traning coach/.omo/evidence/nutricoach-v150-combined/st_01a0560c-r63-installed-wheel-first-claim-qa/venv/lib/python3.12/site-packages/elevenlabs/client.pyis_voice_idr%   %   s    -s344    base_urlc                 @    t        j                  |       j                  S N)httpxURLhost)r'   s    r$   get_base_url_hostr-   )   s    99X###r&   .c                 .     t                fd       }|S )z
    This is a decorator which can be used to mark functions as deprecated.
    It will result in a warning being emitted when the function is used.
    c                  h    t        j                  dj                   dt        d        | i |S NzThe method z7 is deprecated and will be removed in a future version.   )category
stacklevelwarningswarn__name__DeprecationWarningargskwargsfuncs     r$   wrapperzdeprecated.<locals>.wrapper6   s8    $--(_`'	

 T$V$$r&   r   r<   r=   s   ` r$   
deprecatedr?   1   s"    
 4[% % Nr&   c                 .     t                fd       }|S )z
    This is a decorator which can be used to mark async functions as deprecated.
    It will result in a warning being emitted when the function is used.
    c                     K   t        j                  dj                   dt        d        | i | d {   S 7 wr0   r4   r9   s     r$   r=   z!deprecated_async.<locals>.wrapperF   sB     $--(_`'	

 4*6****s   6A >A r   r>   s   ` r$   deprecated_asyncrB   A   s"    
 4[+ + Nr&   c                       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e	 	 d!de
dej                   e
   de
dej                  e
   dej                  e   defd       Ze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jB                  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<   )r'   environmentapi_keytimeouthttpx_clientr'   rG   rH   rI   rJ   c          	          t         |   |xr% t        dt        |       dt        |             xs ||||       t	        | j
                        | _        y )Nzhttps://zwss://)basewss)rG   rH   rI   rJ   )client_wrapper)super__init__r   r-   r   _client_wrappertext_to_speech)selfr'   rG   rH   rI   rJ   	__class__s         r$   rP   zElevenLabs.__init__h   sq     	  % 1( ;<=.x89:
 % 	 
	
 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   rV   rU   rW   rX   voicesaddopenstrjsondumpsgetr   rS   r   rU   rV   rW   rX   fileadd_voice_responses           r$   clonezElevenLabs.clone~   s}    2 "[[__!.34eddD!e4TZZ"-.	 - 
 {{

%
%)  
 	
 5s   A?eleven_multilingual_v2r   Fmp3_44100_128voicevoice_settingsmodeloptimize_streaming_latencystreamoutput_format!pronunciation_dictionary_locatorsrX   textrl   rm   rn   ro   rp   rq   rr   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 )u  
            - 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rX   show_legacyc              3   V   K   | ]   }|j                   k(  s|j                   " y wr)   r   r   .0vrl   s     r$   	<genexpr>z&ElevenLabs.generate.<locals>.<genexpr>   '     "a7M!QRQWQW[`Q`1::7M   ))NVoice  not found.body)r   rm   ro   rq   rs   rX   rr   model_id)r   rm   rq   rs   rX   r   z)Text is neither a string nor an iterator.+Text must be a string when stream is False.r   r   rm   ro   rq   rs   rX   rr   )
isinstancera   r%   r^   get_allnextr   r   r   DEFAULT_VOICEr   r   r   rR   convert_as_streamr   convert_realtimeconvertrS   rs   rl   rm   rn   ro   rp   rq   rr   rX   r   voices_responsemaybe_voice_idr   s     `           r$   generatezElevenLabs.generate   s   v 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)&r7   
__module____qualname____doc__r   
PRODUCTIONosgetenvtypingr   ra   floatr*   ClientrP   r?   Listr   r   rh   r   r   OMITr   r   VoiceId	VoiceNamer   ModelIdr   intr!   r   Sequencer   bytesr   __classcell__)rT   s   @r$   rD   rD   Q   s   2 *.-B-M-M(1		2F(G*,6:^ //#&^ +	^
 %^ '^ ooell3^,  &*9=!
!
 [[!
 	!

 ooc"!
 ~6!
 
!
 !
H 
 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 sr&   rD   c                   x   e Zd ZdZe	 ddedej                  e   dededej                  e	   de
fd	       Ze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j0                  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   rU   rV   rW   rX   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.
        rZ   r[   Nr\   r]   re   s           r$   rh   zAsyncElevenLabs.clone2  s     8 $(;;??!.34eddD!e4TZZ"-.	 $3 $
 
 [[__

%
%) % 
 
 	
 5

s-   BB,BB.BB
BBri   r   Frj   rk   rs   rl   rm   rn   ro   rp   rq   rr   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.
        Tru   Nc              3   V   K   | ]   }|j                   k(  s|j                   " y wr)   rx   ry   s     r$   r|   z+AsyncElevenLabs.generate.<locals>.<genexpr>  r}   r~   r   r   r   r   r   )r   ra   r%   r^   r   r   r   r   r   r   r   r   r   rR   r   r   r   s     `           r$   r   zAsyncElevenLabs.generateY  sk    D 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r)   )r7   r   r   r   rB   ra   r   r   r   r   r   rh   r   r   r   r   r   r   r   r   r   r   r!   r   r   r   r   r   r    r&   r$   r   r     sc   .  :>$
$
 [[$
 	$

 $
 ~6$
 
$
 $
L 
 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 mr&   r   )+r   rb   r"   r   r*   r5   	functoolsr   r   r   r   r   base_clientr
   r   corer   r   typesr   r   r   r   rG   r   realtime_ttsr   r   r   ra   r   r   r   r!   r%   r-   castAnyr   r?   rB   rD   r   r   r&   r$   <module>r      s      	 	    & */ / . 4  #	C4 	
5S 5T 5$ $ $
 v{{6::s#  F FRm) mr&   