a
    B^i                     @   s   d dl mZmZmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlZd dlZd dlZd dlZd dlZG dd deZG dd deZdadadad	d
 Zdd Z dd Z!dd Z"dddZ#dd Z$da%dd Z&dS )    )divisionabsolute_importwith_statementprint_functionunicode_literals)PY2
basestringbchrbordchropenpystrrangeroundstrtobytesunicodeNc                   @   s   e Zd ZdZdS )TTSDonezg
    A subclass of string that is returned from a tts function to stop
    further TTS processing.
    N__name__
__module____qualname____doc__ r   r   7C:\Users\PahaGest\Downloads\Selene\renpy\display\tts.pyr   #   s   r   c                   @   s   e Zd ZdZdS )TTSRootz
    An exception that can be used to cause the TTS system to read the text
    of the root displayable, rather than text of the currently focused
    displayable.
    Nr   r   r   r   r   r   *   s   r    c                   C   s   t d urt  d urd a d S N)processpollr   r   r   r   periodic<   s    r    c                   C   s   t d uS r   )r   r   r   r   r   	is_activeD   s    r!   c                 C   s  t dur0zt   t   W n ty.   Y n0 da |  } | sDdS tjjjdkrzt	j
t	j
j| d W n ty   Y n0 dS tjjjdkrtj  dS tjj}dtjv rttjd || ga n<tjrtjjdu rtd|| ga ntdd|tjj|| ga ntjrbtjjdu rBtd|| ga ntdd|tjj|| ga ntjrtjjdu r~d	}ntjj}tjtjtjd
}| dd} td|||| ||ga nBtj rtjj!rzddl"m#} |d|  W n ty
   Y n0 dS )zM
    Default function which speaks messages using an os-specific method.
    N	clipboardzutf-8debugZRENPY_TTS_COMMANDZespeakz-vsayzdefault voicezsay.vbs"r   Zwscriptr   )calltts)$r   	terminatewait	Exceptionstriprenpygamepreferencesself_voicingpygamescrapput
SCRAP_TEXTencodeexportsrestart_interactionfsencodeosenviron
subprocessPopenlinuxconfig	tts_voice	macintoshwindowspathjoindirnamesys
executablereplace
emscriptenwebaudioZrenpy.audio.webaudior&   )sr7   voiceZsay_vbsr&   r   r   r   default_tts_functionI   sV    

   rK   c                 C   s,   zt j|  W n ty"   Y n0 g adS )zB
    Speaks the queued messages using the specified function.
    N)r,   r=   tts_functionr*   queue)rI   r   r   r   r'      s
    r'   TFc                 C   s.   |st jjjsdS |r"t j| } t|  dS )zL
    This is called by the system to queue the speaking of message `s`.
    N)r,   r-   r.   r/   translationtranslate_stringr'   )rI   	translateforcer   r   r   speak   s
    rR   c                 C   s   | a d S r   )root)dr   r   r   set_root   s    rU   c                 C   s   t jjj}|s2tr*|att jddd dadS d}ts`|a|dkrTt jd}nt jd}t j	j
D ]}|sht jj|rh dS qh| du rt} z|  }W qW q ty   | tu rY dS t} Y q0 q|tkr|at||  dS )	zH
    Causes the TTS system to read the text of the displayable `d`.
    zSelf-voicing disabled.T)rQ   r   Nr"   zClipboard voicing enabled. zSelf-voicing enabled. )r,   r-   r.   r/   old_self_voicingrR   rN   rO   lastr=   tts_voice_channelsaudiomusicget_playingrS   _tts_allr   r'   )rT   r/   prefixirI   r   r   r   displayable   s8    
r_   )TF)'
__future__r   r   r   r   r   renpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   rD   r8   r:   pygame_sdl2r0   r,   r   r*   r   rS   rW   r   r    r!   rK   r'   rR   rU   rV   r_   r   r   r   r   <module>   s&   8	J
