
    2h)3                        S SK r S SKrS SKrS SKrS SKrS SKrS SKJrJr  S SK	J
r
JrJr  S SKJrJrJr  SS/r\R$                  " \5      r\R+                  \R,                  " 5       5         " S S5      r " S	 S5      r " S
 S\5      rg)    N)_fallback_deprecated_lang	tts_langs)	Tokenizerpre_processorstokenizer_cases)_clean_tokens	_minimize_translate_urlgTTS	gTTSErrorc                        \ rS rSrSrSrSrSrg)Speed   z^Read Speed

The Google TTS Translate API supports two speeds:
    Slow: True
    Normal: None
TN )__name__
__module____qualname____firstlineno____doc__SLOWNORMAL__static_attributes__r       @/var/www/auris/envauris/lib/python3.13/site-packages/gtts/tts.pyr   r      s     DFr   r   c                   >   \ rS rSrSrSrSSSS.rSrS	S
SS\R                  \R                  \R                  \R                  /\" \R                  \R                  \R                   \R"                  /5      R$                  S4S jrS rS rS rS rS rS rS rSrg)r   !   a	  gTTS -- Google Text-to-Speech.

An interface to Google Translate's Text-to-Speech API.

Args:
    text (string): The text to be read.
    tld (string): Top-level domain for the Google Translate host,
        i.e `https://translate.google.<tld>`. Different Google domains
        can produce different localized 'accents' for a given
        language. This is also useful when ``google.com`` might be blocked
        within a network but a local or different Google host
        (e.g. ``google.com.hk``) is not. Default is ``com``.
    lang (string, optional): The language (IETF language tag) to
        read the text in. Default is ``en``.
    slow (bool, optional): Reads text more slowly. Defaults to ``False``.
    lang_check (bool, optional): Strictly enforce an existing ``lang``,
        to catch a language error early. If set to ``True``,
        a ``ValueError`` is raised if ``lang`` doesn't exist.
        Setting ``lang_check`` to ``False`` skips Web requests
        (to validate language) and therefore speeds up instantiation.
        Default is ``True``.
    pre_processor_funcs (list): A list of zero or more functions that are
        called to transform (pre-process) text before tokenizing. Those
        functions must take a string and return a string. Defaults to::

            [
                pre_processors.tone_marks,
                pre_processors.end_of_line,
                pre_processors.abbreviations,
                pre_processors.word_sub
            ]

    tokenizer_func (callable): A function that takes in a string and
        returns a list of string (tokens). Defaults to::

            Tokenizer([
                tokenizer_cases.tone_marks,
                tokenizer_cases.period_comma,
                tokenizer_cases.colon,
                tokenizer_cases.other_punctuation
            ]).run

    timeout (float or tuple, optional): Seconds to wait for the server to
        send data before giving up, as a float, or a ``(connect timeout,
        read timeout)`` tuple. ``None`` will wait forever (default).

See Also:
    :doc:`Pre-processing and tokenizing <tokenizer>`

Raises:
    AssertionError: When ``text`` is ``None`` or empty; when there's nothing
        left to speak after pre-processing, tokenizing and cleaning.
    ValueError: When ``lang_check`` is ``True`` and ``lang`` is not supported.
    RuntimeError: When ``lang_check`` is ``True`` but there's an error loading
        the languages dictionary.

d   zhttp://translate.google.com/znMozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36z/application/x-www-form-urlencoded;charset=utf-8)Refererz
User-AgentzContent-TypejQ1olccomenFTNc	                    [        [        5       5      R                  5        H#  u  pU	S:X  a  M  [        R	                  SX5        M%     U(       d   S5       eXl        X l        XPl        X0l        U R                  (       a:  [        U5      U l         [        5       nU R                  U;  a  [        SU-  5      e U(       a  [        R                   U l        O[        R$                  U l        X`l        Xpl        Xl        g ! [         aE  n[        R	                  [        U5      SS9  [        R                  [        U5      5         S nANS nAff = f)Nselfz%s: %szNo text to speakzLanguage not supported: %sT)exc_info)dictlocalsitemslogdebugtexttld
lang_checklangr   r   
ValueErrorRuntimeErrorstrwarningr   r   speedr   pre_processor_funcstokenizer_functimeout)r#   r*   r+   r-   slowr,   r3   r4   r5   kvlangses                r   __init__gTTS.__init__f   s   2 N((*DAF{IIh% + '''t	  %	??1$7DI$!99E)$%AD%HII * DJDJ $7 ,   $		#a&4	0CF##$s   (C? ?
E	;E		Ec                    UR                  5       nU R                   H!  n[        R                  SU5        U" U5      nM#     [	        U5      U R
                  ::  a  [        U/5      $ [        R                  SU R                  5        U R                  U5      n[        U5      n/ nU H  nU[        USU R
                  5      -  nM     U Vs/ s H  oU(       d  M  UPM     nnU$ s  snf )Nzpre-processing: %sztokenizing: %s )	stripr3   r(   r)   lenGOOGLE_TTS_MAX_CHARSr   r4   r	   )r#   r*   pptokens
min_tokensts         r   	_tokenizegTTS._tokenize   s    zz| **BII*B/d8D + t9111 $(( 			"D$7$78$$T* v& 
A)AsD,E,EFFJ  (-Z1!Z- .s   
C$C$c                    [        U R                  SS9nU R                  U R                  5      n[        R                  S[        U5      5        [        R                  S[        U5      5        U(       d   S5       e/ n[        U5       Hl  u  pEU R                  U5      n[        R                  SXF5        [        R                  " SUUU R                  S9nUR                  UR                  5       5        Mn     U$ )	zCreated the TTS API the request(s) without sending them.

Returns:
    list: ``requests.PreparedRequests_``. <https://2.python-requests.org/en/master/api/#requests.PreparedRequest>`_``.
z(_/TranslateWebserverUi/data/batchexecute)r+   pathztext_parts: %sztext_parts: %izNo text to send to TTS APIzdata-%i: %sPOST)methodurldataheaders)r
   r+   rF   r*   r(   r)   r0   r@   	enumerate_package_rpcrequestsRequestGOOGLE_TTS_HEADERSappendprepare)r#   translate_url
text_partsprepared_requestsidxpartrM   rs           r   _prepare_requestsgTTS._prepare_requests   s     'I
 ^^DII.
		"C
O4		"C
O4777z":.IC$$T*DIImS/   !//	A $$QYY[1 /  ! r   c                    XR                   U R                  S/n[        R                  " USS9nU R                  US S///n[        R                  " USS9nSR                  [        R                  R                  U5      5      $ )Nnull),:)
separatorsgenericz	f.req={}&)	r-   r2   jsondumpsGOOGLE_TTS_RPCformaturllibparsequote)r#   r*   	parameterescaped_parameterrpcespaced_rpcs         r   rP   gTTS._package_rpc   sr    99djj&9	 JJyZH$$&7yIJKjj<!!&,,"4"4["ABBr   c                 `    U R                  5        Vs/ s H  oR                  PM     sn$ s  snf )zGet TTS API request bodies(s) that would be sent to the TTS API.

Returns:
    list: A list of TTS API request bodies to make.
)r\   body)r#   prs     r   
get_bodiesgTTS.get_bodies   s)     #'"8"8":;":B":;;;s   +c           	   #   d  #     [         R                  R                  R                  [         R                  R                  R                  R
                  5        U R                  5       n[        U5       GH  u  p# [         R                  " 5        nUR                  US[        R                  R                  5       U R                  S9nSSS5        [        R                  SUWR                  R                   5        [        R                  SX%R                  R"                  5        [        R                  SX%R$                  5        UR'                  5         UR1                  S	S
9 H{  nUR3                  S5      nSU;   d  M  [4        R6                  " SU5      n	U	(       a:  U	R9                  S5      R;                  S5      n
[<        R>                  " U
5      v   Mt  [-        XS9e   [        R                  SU5        GM     g!    GN= f! , (       d  f       GNF= f! [         R                  R(                   a-  n[        R                  [+        U5      5        [-        U WS9eSnAf[         R                  R.                   a,  n[        R                  [+        U5      5        [-        U S9eSnAff = f7f)zyDo the TTS API request(s) and stream bytes

Raises:
    :class:`gTTSError`: When there's an error with the API request.

F)requestverifyproxiesr5   Nzheaders-%i: %sz
url-%i: %szstatus-%i: %s)ttsresponse)ry   i   )
chunk_sizezutf-8r   zjQ1olc","\[\\"(.*)\\"]   asciizpart-%i created) rQ   packagesurllib3disable_warnings
exceptionsInsecureRequestWarningr\   rO   Sessionsendrh   rv   
getproxiesr5   r(   r)   rN   rL   status_coderaise_for_status	HTTPErrorr0   r   RequestException
iter_linesdecoderesearchgroupencodebase64	b64decode)r#   rX   rY   rr   sr[   r:   linedecoded_lineaudio_searchas_bytess              r   streamgTTS.stream   s    	%%66!!))44KK !224 !23GC*%%'1 "$ & 9 9 ; $	  A ( 		*C1B1BC		,YY]];		/3>""$ 5#{{73|+#%99-F#UL##/#5#5a#8#?#?#H$..x88 (D== 6 II'-K 4		
 (' &&00 6		#a&!D155&&77 *		#a&!D))*sm   J0AH  !J0;H9H	BH'J0A?J0 HJ0
H	HJ-8(I  !J-'J((J--J0c                      [        U R                  5       5       H,  u  p#UR                  U5        [        R	                  SX!5        M.     g! [
        [        4 a  n[        S[        U5      -  5      eSnAff = f)a!  Do the TTS API request(s) and write bytes to a file-like object.

Args:
    fp (file object): Any file-like object to write the ``mp3`` to.

Raises:
    :class:`gTTSError`: When there's an error with the API request.
    TypeError: When ``fp`` is not a file-like object that takes bytes.

zpart-%i written to %sz<'fp' is not a file-like object or it does not take bytes: %sN)rO   r   writer(   r)   AttributeError	TypeErrorr0   )r#   fprY   decodedr:   s        r   write_to_fpgTTS.write_to_fp/  sl    	 )$++- 8!		13; !9 	* 	NQTUVQWW 	s   A	A A8A33A8c                     [        [        U5      S5       nU R                  U5        UR                  5         [        R                  SU5        SSS5        g! , (       d  f       g= f)zDo the TTS API request and write result to file.

Args:
    savefile (string): The path and file name to save the ``mp3`` to.

Raises:
    :class:`gTTSError`: When there's an error with the API request.

wbzSaved to %sN)openr0   r   flushr(   r)   )r#   savefilefs      r   save	gTTS.saveD  sE     #h-&!QGGIIImX. '&&s   8A
A%)r-   r,   r3   r2   r*   r5   r+   r4   )r   r   r   r   r   rA   rS   rf   r   
tone_marksend_of_lineabbreviationsword_subr   r   period_commacolonother_punctuationrunr;   rF   r\   rP   rs   r   r   r   r   r   r   r   r   r   !   s    8t 1- J N
 %%&&((##	
 !**,,%%11	
 #+?B:!!FC<6.p*/r   c                   :   ^  \ rS rSrSrSU 4S jjrSS jrSrU =r$ )r   iT  zAException that uses context to present a meaningful error messagec                 8  > UR                  SS 5      U l        UR                  SS 5      U l        U(       a  Xl        O@U R                  b,  U R	                  U R                  U R                  5      U l        OS U l        [
        [        U ]  U R                  5        g )Nry   rz   )popry   rspmsg	infer_msgsuperr   r;   )r#   r   kwargs	__class__s      r   r;   gTTSError.__init__W  sm    ::eT*::j$/HXX!~~dhh9DHDHi'1r   c                    SnUc7  SnUR                   S:w  a$  [        UR                   S9nSR                  U5      nOUR                  nUR                  nSR                  Xg5      nUS:X  a  SnOkUS	:X  a,  UR                   S:w  a  S
R                  UR                   5      nO9US:X  a+  UR
                  (       d  SU R                  R                  -  nOUS:  a  SnSR                  XC5      $ )ziAttempt to guess what went wrong by using known
information (e.g. http response) and observed behaviour

UnknownzFailed to connectr    )r+   zHost '{}' is not reachablez{:d} ({}) from TTS APIi  z!Bad token or upstream API changesi  zUnsupported tld '{}'   z6No audio stream in response. Unsupported language '%s'i  z$Upstream API error. Try again later.z{}. Probable cause: {})r+   r
   rg   r   reasonr,   ry   r-   )r#   ry   r   causepremisehoststatusr   s           r   r   gTTSError.infer_msgb  s    
 ;)Gww%%#''24;;DA
 __FZZF.55fEG};3377e#3.55cgg>3s~~Lhhmm$  3>'..w>>r   )r   r   ry   )N)	r   r   r   r   r   r;   r   r   __classcell__)r   s   @r   r   r   T  s    K	2"? "?r   )r   rd   loggingr   rh   rQ   	gtts.langr   r   gtts.tokenizerr   r   r   
gtts.utilsr   r	   r
   __all__	getLoggerr   r(   
addHandlerNullHandlerr   r   	Exceptionr   r   r   r   <module>r      sz       	   : E E ? ?;
 ! w""$ %	 	p/ p/f	0?	 0?r   