a
    V$c                     @   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   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debugRENPY_TTS_COMMANDespeakz-vsayzdefault voicezsay.vbs"r   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webaudiorenpy.audio.webaudior)   )sr:   voicesay_vbsr)   r   r   r   default_tts_functionI   sV    

   rP   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)rM   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/   r0   r1   r2   translationtranslate_stringr*   )rM   	translateforcer   r   r   speak   s
    rW   c                 C   s   | a d S r   )root)dr   r   r   set_root   s    rZ   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)rV   r   Nr"   zClipboard voicing enabled. zSelf-voicing enabled. )r/   r0   r1   r2   old_self_voicingrW   rS   rT   lastr@   tts_voice_channelsaudiomusicget_playingrX   _tts_allr   r*   )rY   r2   prefixirM   r   r   r   displayable   s8    
rd   )TF)'
__future__r   r   r   r   r   renpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   rG   r;   r=   pygame_sdl2r3   r/   r   r-   r   rX   r\   r   r    r!   rP   r*   rW   rZ   r[   rd   r   r   r   r   <module>   s&   8	J
