%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/speechd/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/speechd/__pycache__/client.cpython-312.pyc

�

�If������dZddlZddlZddlZddlZddlZddlZ	ddlZddl	m
Z
Gd�de�ZGd�de
�ZGd	�d
e�ZGd�de
�ZGd
�de�ZGd�de�ZGd�de
�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�d e�ZGd!�d"e�ZGd#�d$e�ZGd%�d&e�ZGd'�d(e�Zy#ddlZY��xYw))z�Python API to Speech Dispatcher

Basic Python client API to Speech Dispatcher is provided by the 'SSIPClient'
class.  This interface maps directly to available SSIP commands and logic.

A more convenient interface is provided by the 'Speaker' class.

�N�)�pathsc�2�eZdZdZdZ	dZ	dZ	dZ	dZ	dZ	y)	�CallbackTypez5Constants describing the available types of callbacks�index_marks�begin�end�cancel�pause�resumeN)
�__name__�
__module__�__qualname__�__doc__�
INDEX_MARK�BEGIN�END�CANCEL�PAUSE�RESUME���0/usr/lib/python3/dist-packages/speechd/client.pyrr$sE��?��J��
�E�&�
�C�;�
�F��
�E�4�
�F�)rrc��eZdZdZy)�	SSIPErrorz;Common base class for exceptions during SSIP communication.N�r
rrrrrrrr;s��Errc�F��eZdZdZdZd	�fd�	Zd�Zd�Zd�Zd�Z	d�Z
�xZS)
�SSIPCommunicationErrorz?Exception raised when trying to operate on a closed connection.Nc�H��||_||_tt|�di|��y)Nr)�_original_exception�_description�superr�__init__)�self�description�original_exception�kwargs�	__class__s    �rr#zSSIPCommunicationError.__init__Cs%���#5�� �'���
�i��'�1�&�1rc��|jS)z�Return the original exception if any

        If this exception is secondary, being caused by a lower
        level exception, return this original exception, otherwise
        None)r �r$s rr&z)SSIPCommunicationError.original_exceptionHs���'�'�'rc��||_y)zXSet an additional exception
        
        See method additional_exception().
        N��_additional_exception)r$�	exceptions  r�set_additional_exceptionz/SSIPCommunicationError.set_additional_exceptionPs��
&/��"rc��|jS)z�Return an additional exception
        
        Additional exceptions araise from failed attempts to resolve
        the former problemr,r*s r�additional_exceptionz+SSIPCommunicationError.additional_exceptionWs��
�)�)�)rc��|jS)zReturn error description)r!r*s rr%z"SSIPCommunicationError.description^s��� � � rc�b�g}|j�r|j|j��|jr+|jdt|j��z�|jr+|jdt|j	��z�dj|�S)NzOriginal error: zAdditional error: �
)r%�appendr&�strr1�join)r$�msgss  r�__str__zSSIPCommunicationError.__str__bs����������K�K��(�(�*�+��"�"��K�K�*�S��1H�1H�1J�-K�K�L��$�$��K�K�,�s�4�3L�3L�3N�/O�O�P��y�y���r�NN)r
rrrr-r#r&r/r1r%r9�
__classcell__�r(s@rrr>s*���I� ��2�
(�/�*�!�rrc��eZdZd�Zd�Zd�Zy)�SSIPResponseErrorc�d�tj||�d|���||_||_||_y)Nz: )�	Exceptionr#�_code�_msg�_data�r$�code�msg�datas    rr#zSSIPResponseError.__init__ms,�����4�T�3�!7�8���
���	���
rc��|jS)z8Return the server response error code as integer number.)rAr*s rrEzSSIPResponseError.codes����z�z�rc��|jS)z/Return server response error message as string.)rBr*s rrFzSSIPResponseError.msgws���y�y�rN)r
rrr#rErFrrrr>r>ls����rr>c��eZdZdZd�Zy)�SSIPCommandErrorz9Exception raised on error response after sending command.c��|jS)z7Return the command string which resulted in this error.�rCr*s r�commandzSSIPCommandError.commandrIrN)r
rrrrOrrrrLrL|s
��C�rrLc��eZdZdZd�Zy)�
SSIPDataErrorz6Exception raised on error response after sending data.c��|jS)z-Return the data which resulted in this error.rNr*s rrGzSSIPDataError.data�rIrN)r
rrrrGrrrrQrQ�s
��@�rrQc��eZdZdZy)�
SpawnErrorz&Indicates failure in server autospawn.NrrrrrTrT�s��0rrTc��eZdZdZdZ	dZy)�CommunicationMethodzBConstants describing the possible methods of connection to server.�unix_socket�inet_socketN�r
rrr�UNIX_SOCKET�INET_SOCKETrrrrVrV�s��L��K�;��K�9rrVc��eZdZdZdZdZdZeezezZeezezZeezZ	eezZ
ejejejejej ej"d�Zd�Zd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zy)�_SSIP_Connectionz/Implementation of low level SSIP communication.s
�.s..)i�i�i�i�i�i�c��|tjk(rtj}|}nL|tjk(r.|r|sJ�tj
}tj|�|f}ntd��	tj|tj�|_	|jj|�d|_
g|_d|_t!j"d�|_t!j&|j(idd�	�|_|j*j-�y#tj$r}td|z|���d}~wwxYw)
z�Init connection: open the socket to server,
        initialize buffers, launch a communication handling
        thread.
        z Unsupported communication methodzCan't open socket using method )r&Nrrz SSIP client communication threadT)�targetr'�name�daemon)rVrZ�socket�AF_UNIXr[�AF_INET�
gethostbyname�
ValueError�SOCK_STREAM�_socket�connect�errorr�_buffer�_com_buffer�	_callback�	threading�	Semaphore�_ssip_reply_semaphore�Thread�_communication�_communication_thread�start)r$�communication_method�socket_path�host�port�
socket_family�socket_connect_args�exs        rr#z_SSIP_Connection.__init__�s2�� �#6�#B�#B�B�"�N�N�M�"-��
!�%8�%D�%D�
D��D� �=�"�N�N�M�#)�#7�#7��#=�t�"D���?�@�@�	B�!�=�=���8J�8J�K�D�L��L�L� � �!4�5����������%.�%8�%8��%;��"�� � ��(;�(;�B�&H�(,�.�	
�"�	
�"�"�(�(�*���|�|�	B�(�)J�+?�*@�>@�B�
B��	B�s�4AD*�*E�=E
�
Ec���	|jjtj�|jj�|jj�y#tj$rY�JwxYw)z>Close the server connection, destroy the communication thread.N)ri�shutdownrc�	SHUT_RDWRrk�closertr7r*s rr�z_SSIP_Connection.close�s[��	��L�L�!�!�&�"2�"2�3�	
�������"�"�'�'�)��	�|�|�	��	�s�)A � A6�5A6c��		|j�\}}}dzdk7r9|jj|f�|jj��W|j�W|j|}|tjk(rddi}ni}ttdd�\}}|j|||fi|����#t$rtj�Y��wxYw)a*Handle incoming socket communication.

        Listens for all incoming communication on the socket, dispatches
        events and puts all other replies into self._com_buffer list in the
        already parsed form as (code, msg, data).  Each time a new item is
        appended to the _com_buffer list, the corresponding semaphore
        'self._ssip_reply_semaphore' is incremented.

        This method is designed to run in a separate thread.  The thread can be
        interrupted by closing the socket on which it is listening for
        reading.�d�N�
index_mark�)�
_recv_message�IOError�sys�exitrmr5rq�releasern�_CALLBACK_TYPE_MAPrr�map�int)r$rErFrG�typer'�msg_id�	client_ids        rrsz_SSIP_Connection._communication�s����
�"&�"4�"4�"6���c�4��S�y�A�~�� � �'�'��s�D�(9�:��*�*�2�2�4���~�~�)��.�.�t�4���<�2�2�2�*�D��G�4�F��F�$'��T�"�1�X�$6�!��	�����v�y�$�A�&�A�)���
����
�
�s�B<�<C�Cc���|jj|j�}|dk(rp	|jj	d�}t
|�dk(rt
�|xj|z
c_|jj|j�}|dk(r�p|jd|}|j|t
|j�zd|_|jd�S#t
�xYw)zuRead one whole line from the socket.

        Blocks until the line delimiter ('_NEWLINE') is read.
        
        ���irN�utf-8)rl�find�_NEWLINEri�recvr��len�decode)r$�pointer�d�lines    r�	_readlinez_SSIP_Connection._readline�s����,�,�#�#�D�M�M�2����m�
��L�L�%�%�d�+���1�v��{��
��L�L�A��L��l�l�'�'��
�
�6�G���m��|�|�H�W�%���|�|�G�C��
�
�,>�$>�$?�@����{�{�7�#�#��
��
�s�C%�%C-c��g}d}	|j�}t|�dk\sJd��|dd|d|dd}}}|j�r|�||k(r|dvsJd��|dk(r|}t|�|t	|�fS|}|j|���)zTRead server response or a callback
        and return the triplet (code, msg, data).N�z$Malformed data received from server!�)�-� r�)r�r��isalnumr��tupler5)r$rG�cr�rE�sep�textrFs        rr�z_SSIP_Connection._recv_messages���������>�>�#�D��t�9��>�I�#I�I�>�"�2�A�h��Q���a�b��t�#�D��<�<�>�q�y�D�A�I��*�$�
M�&L�
M�%��c�z����4�y�#�u�T�{�2�2��A��K�K���rc��|jj�st�|jj	�|j
d}|j
d=|S)zdRead server response from the communication thread
        and return the triplet (code, msg, data).r)rt�is_aliverrq�acquirerm)r$�responses  r�_recv_responsez_SSIP_Connection._recv_response!sQ��
�)�)�2�2�4�(�(��"�"�*�*�,��#�#�A�&�����Q���rc	���	|dvr:|dtjtjfvst|dt�sJ�dj|ft
tt|��z�}	|jj|jd�|jz�|j!�\}}}|dzdk7r
t#|||��|||fS#tj$rtd��wxYw)a�Send SSIP command with given arguments and read server response.

        Arguments can be of any data type -- they are all stringified before
        being sent to the server.

        Returns a triplet (code, msg, data), where 'code' is a numeric SSIP
        response code as an integer, 'msg' is an SSIP rsponse message as string
        and 'data' is a tuple of strings (all lines of response data) when a
        response contains some data.
        
        'SSIPCommandError' is raised in case of non 2xx return code.  See SSIP
        documentation for more information about server responses and codes.

        'IOError' is raised when the socket was closed by the remote side.
        
        )�SETr�STOPrr�r��"Speech Dispatcher connection lost.r�r�)�Scope�SELF�ALL�
isinstancer�r7r�r�r6ri�send�encoder�rcrkrr�rL)r$rO�args�cmdrErFrGs       r�send_commandz_SSIP_Connection.send_command.s���"��4�4��A�w�5�:�:�u�y�y�"9�9�$�T�!�W�c�2�3�3��h�h��z�E�#�c�4�.�$9�9�:��	O��L�L���c�j�j��1�D�M�M�A�B��-�-�/���c�4���9��>�"�4��c�2�2��S�$�����|�|�	O�(�)M�N�N�	O�s�-7C�C1c���|jd�}|j|j�r't|j�}|j||dz}|j|j|j�}	|jj||jz�|j�\}}}|dzdk7r
t|||��|||fS#tj$rtd��wxYw)apSend multiline data and read server response.

        Returned value is the same as for 'send_command()' method.

        'SSIPDataError' is raised in case of non 2xx return code. See SSIP
        documentation for more information about server responses and codes.
        
        'IOError' is raised when the socket was closed by the remote side.
        
        r�Nr�r�r�)r��
startswith�_END_OF_DATA_MARKERr��_END_OF_DATA_MARKER_ESCAPED�replace�_RAW_DOTLINE�_ESCAPED_DOTLINErir��_END_OF_DATArcrkrr�rQ)r$rG�lrErF�
response_datas      r�	send_dataz_SSIP_Connection.send_dataMs����{�{�7�#���?�?�4�3�3�4��D�,�,�-�A��3�3�d�1�2�h�>�D��|�|�D�-�-�t�/D�/D�E��	O��L�L���d�T�%6�%6�6�7�$(�#6�#6�#8� ��c�=���9��>���c�4�0�0��S�-�'�'���|�|�	O�(�)M�N�N�	O�s�;(C�C0c��||_y)a~Register a callback function for handling asynchronous events.

        Arguments:
          callback -- a callable object (function) which will be called to
            handle asynchronous events (arguments described below).  Passing
            `None' results in removing the callback function and ignoring
            events.  Just one callback may be registered.  Attempts to register
            a second callback will result in the former callback being
            replaced.

        The callback function must accept three positional arguments
        ('message_id', 'client_id', 'event_type') and an optional keyword
        argument 'index_mark' (when INDEX_MARK events are turned on).

        Note, that setting the callback function doesn't turn the events on.
        The user is responsible to turn them on by sending the appropriate `SET
        NOTIFICATION' command.

        N)rn)r$�callbacks  r�set_callbackz_SSIP_Connection.set_callbackns��("��rN)r
rrrr�r�r�r��_END_OF_DATA_ESCAPEDr�r�rrrrrrrr�r#r�rsr�r�r�r�r�r�rrrr]r]�s���9��H���"'���1�1�H�<�L�#�&A�A�H�L���1�1�L��"=�=��+�6�6�+�1�1�+�/�/�+�2�2�+�1�1�+�2�2��� +�D
*�!B�H$�(�"��>(�B"rr]c�"�eZdZdZd�Zd�Zd�Zy)�_CallbackHandlerz(Internal object which handles callbacks.c�R�||_i|_tj�|_y�N)�
_client_id�
_callbacksro�Lock�_lock)r$r�s  rr#z_CallbackHandler.__init__�s��#�������^�^�%��
rc��||jk7ry|jj�		|j|\}}|�||vr	||fi|��|tj
tjfvr|j|=	|jj�y#t$rY�&wxYw#|jj�wxYwr�)	r�r�r�r�rrr�KeyErrorr�)r$r�r�r�r'r��event_typess       r�__call__z_CallbackHandler.__call__�s�������'���
�
����	!�
0�(,����(?�%��+��&�$�+�*=��T�,�V�,��L�,�,�l�.A�.A�B�B�����/��J�J��� ���
��
��
�J�J��� �s(�B�?B(�	B%�"B(�$B%�%B(�(Cc���|jj�	||f|j|<|jj�y#|jj�wxYwr�)r�r�r�r�)r$r�r�r�s    r�add_callbackz_CallbackHandler.add_callback�sK���
�
����	!�'/��&=�D�O�O�F�#��J�J��� ��D�J�J��� �s�A�A$N)r
rrrr#r�r�rrrr�r��s��2�&�
!�$!rr�c��eZdZdZdZ	dZy)r�z�An enumeration of valid SSIP command scopes.

    The constants of this class should be used to specify the 'scope' argument
    for the 'Client' methods.

    r$�allN)r
rrrr�r�rrrr�r��s����D�L�
�C�Krr�c�$�eZdZdZdZdZdZdZdZy)�PriorityaAn enumeration of valid SSIP message priorities.

    The constants of this class should be used to specify the 'priority'
    argument for the 'Client' methods.  For more information about message
    priorities and their interaction, see the SSIP documentation.
    
    �	importantr��message�notification�progressN)	r
rrr�	IMPORTANT�TEXT�MESSAGE�NOTIFICATION�PROGRESSrrrr�r��s"����I��D��G�!�L��Hrr�c�&�eZdZdZdZ	dZ	dZ	dZy)�PunctuationModezkConstants for selecting a punctuation mode.

    The mode determines which characters should be read.

    r��none�some�mostN)r
rrrr��NONE�SOME�MOSTrrrr�r��s+���
�C�*��D�6��D�H��D�rr�c��eZdZdZdZ	dZy)�DataModezWConstants specifying the type of data contained within messages
    to be spoken.

    r��ssmlN)r
rrrr��SSMLrrrr�r��s����D���D�:rr�c��eZdZdZdZ	dZ	dZ				d/d�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd0d�Zd�Zd�Zd�Zej(fd�Zej(fd�Zej(fd�Zej(fd�Zd�Zd0d�Zej(fd�Zd�Zej(fd�Zd�Zej(fd�Zd�Z ej(fd�Z!ej(fd�Z"d �Z#ej(fd!�Z$d"�Z%ej(fd#�Z&d$�Z'ej(fd%�Z(ej(fd&�Z)ej(fd'�Z*ej(fd(�Z+ej(fd)�Z,d*�Z-d+�Z.d,�Z/d-�Z0d.�Z1y)1�
SSIPClientaLBasic Speech Dispatcher client interface.

    This class provides a Python interface to Speech Dispatcher functionality
    over an SSIP connection.  The API maps directly to available SSIP commands.
    Each connection to Speech Dispatcher is represented by one instance of this
    class.
    
    Many commands take the 'scope' argument, thus it is shortly documented
    here.  It is either one of 'Scope' constants or a number of connection.  By
    specifying the connection number, you are applying the command to a
    particular connection.  This feature is only meant to be used by Speech
    Dispatcher control application, however.  More datails can be found in
    Speech Dispatcher documentation.

    Here is a simple example:

    from speechd import client
    c = client.SSIPClient("mytest")
    c.speak("hello, world!")
    z	127.0.0.1i�zspeech-dispatcher/speechd.sockNc

��tjjd�}
tjj	dtjj	dtjj|
d���}tjj||j�}tj||j|jd�}
|xstjj	d�}|r!|
j|j|��n�tjj	d�}	ttjj	d��}tjj	d
�}|r||
d<|r||
d<n|r||
d<|	r|	|
d
<n|r||
d
<|j|
|�|j|||�y	#d	}Y�pxYw)a[Initialize the instance and connect to the server.

        Arguments:
          name -- client identification string
          component -- connection identification string.  When one client opens
            multiple connections, this can be used to identify each of them.
          user -- user identification string (user name).  When multi-user
            access is expected, this can be used to identify their connections.
          address -- server address as specified in Speech Dispatcher
            documentation (e.g. "unix:/run/user/joe/speech-dispatcher/speechd.sock"
            or "inet:192.168.0.85:6561")
          autospawn -- a flag to specify whether the library should
            try to start the server if it determines its not already
            running or not

        Deprecated arguments:
          method -- communication method to use, one of the constants defined in class
            CommunicationMethod
          socket_path -- for CommunicationMethod.UNIX_SOCKET, socket
            path in filesystem. By default, this is $XDG_RUNTIME_DIR/speech-dispatcher/speechd.sock
            where $XDG_RUNTIME_DIR is determined using the XDG Base Directory
            Specification.
          host -- for CommunicationMethod.INET_SOCKET, server hostname
            or IP address as a string.  If None, the default value is
            taken from SPEECHD_HOST environment variable (if it
            exists) or from the DEFAULT_HOST attribute of this class.
          port -- for CommunicationMethod.INET_SOCKET method, server
            port as number or None.  If None, the default value is
            taken from SPEECHD_PORT environment variable (if it
            exists) or from the DEFAULT_PORT attribute of this class.
         
        For more information on client identification strings see Speech
        Dispatcher documentation.
        �~�XDG_RUNTIME_DIR�XDG_CACHE_HOMEz.cache)rvrwrxry�SPEECHD_ADDRESS�SPEECHD_HOST�SPEECHD_PORTN�SPEECHD_SOCKET�methodryrw)�os�path�
expanduser�environ�getr7�DEFAULT_SOCKET_PATHrVrZ�DEFAULT_HOST�DEFAULT_PORT�update�"_connection_arguments_from_addressr��_connect_with_autospawn�_initialize_connection)r$ra�	component�user�address�	autospawnrxryr�rw�_home�_runtime_dir�
_sock_path�connection_args�_address�env_speechd_host�env_speechd_port�env_speechd_socket_paths                  rr#zSSIPClient.__init__�s���N���"�"�3�'���z�z�~�~�&7������HX�Z\�Za�Za�Zf�Zf�gl�nv�Zw�9x�y���W�W�\�\�,��0H�0H�I�
�3F�3R�3R�*4�#'�#4�#4�#'�#4�#4����?�b�j�j�n�n�->�?����"�"�4�#J�#J�8�#T�U�
 "�z�z�~�~�n�=��
(�#&�r�z�z�~�~�n�'E�#F� �')�j�j�n�n�5E�&F�#��,2���)��*.���'�!�*:���'��1<��
�.�(�1H��
�.��$�$�_�i�@��#�#�D�$�	�:��#
(�#'� �s�5(G�G
c���	tdi|��|_y#t$rX}|dk7rH	|j|�n$#t$r}|j|�|�d}~wwxYwtdi|��|_n�Yd}~yd}~wwxYw)z2Establish new connection (and/or autospawn server)FNr)r]�_connr�
_server_spawnrTr/)r$r
r	�ce�ses     rrz"SSIPClient._connect_with_autospawnKs}��	�)�<�O�<�D�J��%�	��E�!���&�&��7��!���/�/��3��H����.�@��@��
����	�s3��	A4�A/�4�A/�	A�A�A�A/�/A4c�V�|�d|�d|��}|jjdtjd|�|jjddd�\}}}t	|d�|_t
|j
�|_|jj|j�tjtjtjtjtjtjfD]!}|jjddd	|d
��#y)zIInitialize connection -- Set client name, get id, register callbacks etc.�:r��CLIENT_NAME�HISTORY�GET�	CLIENT_IDrr$r��onN)rr�r�r�r�r�r��_callback_handlerr�rrrrrrr)	r$rrar�	full_namerErFrG�events	         rrz!SSIPClient._initialize_connection]s���"&��i�8�	��
�
����u�z�z�=�)�L��*�*�1�1�)�U�K�P���c�4��d�1�g�,���!1�$�/�/�!B����
�
���� 6� 6�7�"�-�-�"�(�(�"�&�&�"�)�)�"�(�(�"�)�)�+�	P�E�
�J�J�#�#�E�6�>�5�$�O�
	Prc�t�i}|jd�}	|d}||d<|tjk(r	|d|d<|S|tj
k(r	|d|d<t
|d�|d	<|Std��#td��xYw#t$rY|SwxYw#t$rtd
��t$rY|SwxYw)z^Parse a Speech Dispatcher address line and return a dictionary
        of connection argumentsrrzWrong format of server addressrvrrwrxr�ryz<Third parameter of inet_socket address must be a port numberz(Unknown communication method in address.)	�split�SSIPCommunicationErrrorrVrZ�
IndexErrorr[r�rgr)r$rr
�address_params�_methods     rrz-SSIPClient._connection_arguments_from_addressms
���� ���s�+��	L�$�Q�'�G�3:��.�/��)�5�5�5�
�1?��1B��
�.����+�7�7�
7�
�*8��*;���'�*-�n�Q�.?�*@���'���)�)S�T�T��#	L�)�*J�K�K��
�
����
���
m�,�-k�l�l��
����	
�s.�A7�B�B�7
B�	B�B�B7�6B7c�$�|j�y)zClose the connectionN)r�r*s r�__del__zSSIPClient.__del__�s���
�
�rc�0�|ddk(rxtj|d|d�}|D�cgc]
}|dd��}}d}|D] }|jd�s|d	k(s�||d<d
}�"|std|d�dt	|��d
���tjd�}|stj}t
jj|�r�g}|j�D]-\}	}
|	dvs�|d|	jdd�zt	|
�gz
}�/tj|dg|zdtjtj��}|j!�\}}
|j#�}|dk7rtd|
����|j$Std|z��cc}w)z/Attempts to spawn the speech-dispatcher server.rvrXrxryr�rFz127.z::1Tz@Can't start server automatically (autospawn), requested address z
 resolves on zj which seems to be a remote host. You must start the server manually or choose another connection address.�SPEECHD_CMD)rxz--�_r�z--spawnN)�stdin�stdout�stderrz2Server refused to autospawn, stating this reason: z-Can't find Speech Dispatcher spawn command %s)rc�getaddrinfor�rTr6r��getenvr�
SPD_SPAWN_CMDr��exists�itemsr��
subprocess�Popen�PIPE�communicate�wait�pid)r$r
�	addrinfos�addrinfo�ip_addresses�	localhost�ipr��connection_params�param�value�server�stdout_reply�stderr_reply�retcodes               rrzSSIPClient._server_spawn�s����1�2�m�C��*�*�?�6�+B�+:�6�+B�D�I�<E�E�x�H�Q�K��N�E�L�E��I�"�
#���=�=��(�B�%�K�.0�O�F�+�"�I�
#��!�P_�_e�Of�OR�S_�O`�c�d�d�
�i�i�
�&����%�%�C�
�7�7�>�>�#�� "�� /� 5� 5� 7�
S���u��	�)�%�$�u�}�}�S��/E�*E�s�5�z�)R�R�%�
S� �%�%�s�I�&6�7H�&H�,0����Q[�Q`�Q`�b�F�)/�);�);�)=�&�L�,��k�k�m�G��!�|� �[g�!i�j�j��:�:���L�,/�1�2�
2��?Fs�Fc��|tjtjtjtjtj
fvsJ|��|jjdtjd|�y)z�Set the priority category for the following messages.

        Arguments:
          priority -- one of the 'Priority' constants.

        r��PRIORITYN)
r�r�r�r�r�r�rr�r�r�)r$�prioritys  r�set_priorityzSSIPClient.set_priority�si���H�.�.��0@�0@�$�M�M�8�+@�+@�$�-�-�/�/�	9�08�	9�/�	
�
�
����u�z�z�:�x�Hrc���|tjk(rd}n$|tjk(rd}ntd|z��|jjdtjd|�y)z�Set the data mode for further speech commands.

        Arguments:
          value - one of the constants defined by the DataMode class.

        r�offz?Value "%s" is not one of the constants from the DataMode class.r��	SSML_MODEN)r�r�r�rgrr�r�r�)r$rA�ssip_vals   r�
set_data_modezSSIPClient.set_data_mode�s\���H�M�M�!��H�
�h�m�m�
#��H��Q����
�	
�
�
����u�z�z�;��Irc���|jjd�|jj|�}|r.t|dd�}|jj|||�|S)a�Say given message.

        Arguments:
          text -- message text to be spoken.  This may be either a UTF-8
            encoded byte string or a Python unicode string.
          callback -- a callback handler for asynchronous event notifications.
            A callable object (function) which accepts one positional argument
            `type' and one keyword argument `index_mark'.  See below for more
            details.
          event_types -- a tuple of event types for which the callback should
            be called.  Each item must be one of `CallbackType' constants.
            None (the default value) means to handle all event types.  This
            argument is irrelevant when `callback' is not used.

        The callback function will be called whenever one of the events occurs.
        The event type will be passed as argument.  Its value is one of the
        `CallbackType' constants.  In case of an index mark event, additional
        keyword argument `index_mark' will be passed and will contain the index
        mark identifier as specified within the text.

        The callback function should not perform anything complicated and is
        not allowed to issue any further SSIP client commands.  An attempt to
        do so would lead to a deadlock in SSIP communication.

        This method is non-blocking;  it just sends the command, given
        message is queued on the server and the method returns immediately.

        �SPEAKr�r)rr�r�r�rr�)r$r�r�r��resultr�s      r�speakzSSIPClient.speak�s^��:	
�
�
����(����%�%�d�+�������1��&�F�
�"�"�/�/���+�N��
rc�\�|jjd|jdd��y)a>Say given character.

        Arguments:
          char -- a character to be spoken.  Either a Python unicode string or
            a UTF-8 encoded byte string.

        This method is non-blocking;  it just sends the command, given
        message is queued on the server and the method returns immediately.

        �CHARr��spaceN)rr�r�)r$�chars  rrVzSSIPClient.char�s#��	
�
�
�������S�'�(B�Crc�<�|jjd|�y)aSay given key name.

        Arguments:
          key -- the key name (as defined in SSIP); string.

        This method is non-blocking;  it just sends the command, given
        message is queued on the server and the method returns immediately.

        �KEYN�rr�)r$�keys  rrZzSSIPClient.key	s��	
�
�
����s�+rc�<�|jjd|�y)aOutput given sound_icon.

        Arguments:
          sound_icon -- the name of the sound icon as defined by SSIP; string.

        This method is non-blocking; it just sends the command, given message
        is queued on the server and the method returns immediately.

        �
SOUND_ICONNrY)r$�
sound_icons  rr]zSSIPClient.sound_icons��	
�
�
����j�9rc�<�|jjd|�y)z�Immediately stop speaking and discard messages in queues.

        Arguments:
          scope -- see the documentation of this class.
            
        rNrY�r$�scopes  rr
zSSIPClient.cancel!s��	
�
�
����%�0rc�<�|jjd|�y)z�Immediately stop speaking the currently spoken message.

        Arguments:
          scope -- see the documentation of this class.
        
        r�NrYr_s  r�stopzSSIPClient.stop+s��	
�
�
�����.rc�<�|jjd|�y)a=Pause speaking and postpone other messages until resume.

        This method is non-blocking.  However, speaking can continue for a
        short while even after it's called (typically to the end of the
        sentence).

        Arguments:
          scope -- see the documentation of this class.
        
        rNrYr_s  rrzSSIPClient.pause4s��	
�
�
�����/rc�<�|jjd|�y)a6Resume speaking of the currently paused messages.

        This method is non-blocking.  However, speaking can continue for a
        short while even after it's called (typically to the end of the
        sentence).

        Arguments:
          scope -- see the documentation of this class.
        
        rNrYr_s  rrzSSIPClient.resumeAs��	
�
�
����%�0rc�F�|jjdd�\}}}|S)z@Return names of all active output modules as a tuple of strings.�LIST�OUTPUT_MODULESrYrDs    r�list_output_moduleszSSIPClient.list_output_modulesNs$���*�*�1�1�&�:J�K���c�4��rc��	ddg}|r$|j|�|r|j|�|jj|�\}}}d�}t	|D�cgc]
}||���c}�S#t$rYywxYwcc}w)a�Return names of all available voices for the current output module.

        If language (possibly even variant) is set, only the list matching that
        language (possibly even variant) is returned.

        Returns a tuple of tripplets (name, language, variant).

        'name' is a string, 'language' is an ISO 639-1 Alpha-2/3 language code
        and 'variant' is a string.  Language and variant may be None.

        rf�SYNTHESIS_VOICESrc�Z�t|jdd��\}}}||xsd|xsdfS)N�	r�)r��rsplit)�itemra�lang�variants    rr"z/SSIPClient.list_synthesis_voices.<locals>.spliths3��"'����D�!�(<�"=��D�$���$�,�$���4�8�8r)r5rr�rLr�)	r$�languagerprOrErFrGr"rns	         r�list_synthesis_voicesz SSIPClient.list_synthesis_voicesSs���	��1�2�G�����x�(���N�N�7�+�5�d�j�j�5�5�w�?�O�D�#�t�	9��d�3�d�e�D�k�3�4�4�� �	��	��
4s�AA+�A:�+	A7�6A7c�d�t|t�sJ�|jjd|d|�y)aSwitch to a particular language for further speech commands.

        Arguments:
          language -- two/three letter language code according to RFC 1766 as string, possibly with a region qualification.
          scope -- see the documentation of this class.
            
        r��LANGUAGEN)r�r6rr�)r$rqr`s   r�set_languagezSSIPClient.set_languagems,���(�C�(�(�(��
�
����u�j�(�Crc�R�|jjdd�\}}}|r|dSy)zGet the current language.rrtrNrYrDs    r�get_languagezSSIPClient.get_languagexs-���*�*�1�1�%��D���c�4����7�N�rc�@�|jjd|d|�y)z�Switch to a particular output module.

        Arguments:
          name -- module (string) as returned by 'list_output_modules()'.
          scope -- see the documentation of this class.
        
        r��
OUTPUT_MODULENrY)r$rar`s   r�set_output_modulezSSIPClient.set_output_modules��	
�
�
����u�o�t�Drc�R�|jjdd�\}}}|r|dSy)zGet the current output module.rryrNrYrDs    r�get_output_modulezSSIPClient.get_output_module�s-���*�*�1�1�%��I���c�4����7�N�rc��t|t�rd|cxkrdksJ|��J|��|jjd|d|�y)a�Set the pitch for further speech commands.

        Arguments:
          value -- integer value within the range from -100 to 100, with 0
            corresponding to the default pitch of the current speech synthesis
            output module, lower values meaning lower pitch and higher values
            meaning higher pitch.
          scope -- see the documentation of this class.
          
        ���r�r��PITCHN�r�r�rr��r$rAr`s   r�	set_pitchzSSIPClient.set_pitch�sK���%��%�$�%�*>�3�*>�E��E�>�*>�E��E�>��
�
����u�g�u�=rc�R�|jjdd�\}}}|r|dSy)zGet the current pitch.rrrNrYrDs    r�	get_pitchzSSIPClient.get_pitch�s-���*�*�1�1�%��A���c�4����7�N�rc��t|t�rd|cxkrdksJ|��J|��|jjd|d|�y)a�Set the pitch range for further speech commands.

        Arguments:
          value -- integer value within the range from -100 to 100, with 0
            corresponding to the default pitch range of the current speech synthesis
            output module, lower values meaning lower pitch range and higher values
            meaning higher pitch range.
          scope -- see the documentation of this class.
          
        r~r�r��PITCH_RANGENr�r�s   r�set_pitch_rangezSSIPClient.set_pitch_range�sK���%��%�$�%�*>�3�*>�E��E�>�*>�E��E�>��
�
����u�m�U�Crc��t|t�rd|cxkrdksJ�J�|jjd|d|�y)a�Set the speech rate (speed) for further speech commands.

        Arguments:
          value -- integer value within the range from -100 to 100, with 0
            corresponding to the default speech rate of the current speech
            synthesis output module, lower values meaning slower speech and
            higher values meaning faster speech.
          scope -- see the documentation of this class.
            
        r~r�r��RATENr�r�s   r�set_ratezSSIPClient.set_rate�sA���%��%�$�%�*>�3�*>�>�>�*>�>�>��
�
����u�f�e�<rc�R�|jjdd�\}}}|r|dSy)z$Get the current speech rate (speed).rr�rNrYrDs    r�get_ratezSSIPClient.get_rate�s-���*�*�1�1�%��@���c�4����7�N�rc��t|t�rd|cxkrdksJ�J�|jjd|d|�y)awSet the speech volume for further speech commands.

        Arguments:
          value -- integer value within the range from -100 to 100, with 100
            corresponding to the default speech volume of the current speech
            synthesis output module, lower values meaning softer speech.
          scope -- see the documentation of this class.
            
        r~r�r��VOLUMENr�r�s   r�
set_volumezSSIPClient.set_volume�sA���%��%�$�%�*>�3�*>�>�>�*>�>�>��
�
����u�h��>rc�R�|jjdd�\}}}|r|dSy)zGet the speech volume.rr�rNrYrDs    r�
get_volumezSSIPClient.get_volume�s-���*�*�1�1�%��B���c�4����7�N�rc���|tjtjtjtjfvsJ|��|j
j
d|d|�y)z�Set the punctuation pronunciation level.

        Arguments:
          value -- one of the 'PunctuationMode' constants.
          scope -- see the documentation of this class.
            
        r��PUNCTUATIONN)r�r�r�r�r�rr�r�s   r�set_punctuationzSSIPClient.set_punctuation�sa����,�,�o�.B�.B�(�-�-��/C�/C�E�E�	L�FK�	L�E��
�
����u�m�U�Crc�R�|jjdd�\}}}|r|dSy)z(Get the punctuation pronunciation level.rr�rNrYrDs    r�get_punctuationzSSIPClient.get_punctuation�s-���*�*�1�1�%��G���c�4����7�N�rc��|dvsJ�|dk(r|jjd|dd�y|jjd|dd�y)a,Toggle the spelling mode or on off.

        Arguments:
          value -- if 'True', all incoming messages will be spelled
            instead of being read as normal words. 'False' switches
            this behavior off.
          scope -- see the documentation of this class.
            
        )TFTr��SPELLINGrrKNrYr�s   r�set_spellingzSSIPClient.set_spelling�sI���
�%�%�%��D�=��J�J�#�#�E�5�*�d�C��J�J�#�#�E�5�*�e�Drc�L�|dvsJ�|jjd|d|�y)a�Set capital letter recognition mode.

        Arguments:
          value -- one of 'none', 'spell', 'icon'. None means no signalization
            of capital letters, 'spell' means capital letters will be spelled
            with a synthetic voice and 'icon' means that the capital-letter icon
            will be prepended before each capital letter.
          scope -- see the documentation of this class.
            
        )r��spell�iconr��CAP_LET_RECOGNNrYr�s   r�set_cap_let_recognzSSIPClient.set_cap_let_recogn�s,���1�1�1�1��
�
����u�.>��Frc��t|t�r|j�dvsJ�|jj	d|d|�y)a�Set voice by a symbolic name.

        Arguments:
          value -- one of the SSIP symbolic voice names: 'MALE1' .. 'MALE3',
            'FEMALE1' ... 'FEMALE3', 'CHILD_MALE', 'CHILD_FEMALE'
          scope -- see the documentation of this class.

        Symbolic voice names are mapped to real synthesizer voices in the
        configuration of the output module.  Use the method
        'set_synthesis_voice()' if you want to work with real voices.
            
        )�male1�male2�male3�female1�female2�female3�
child_male�child_femaler��
VOICE_TYPEN)r�r6�lowerrr�r�s   r�	set_voicezSSIPClient.set_voice
sE���%��%��{�{�}�!1�1�	1�1�	
�
�
����u�l�E�Brc�@�|jjd|d|�y)z�Set voice by its real name.

        Arguments:
          value -- voice name as returned by 'list_synthesis_voices()'
          scope -- see the documentation of this class.
            
        r��SYNTHESIS_VOICENrYr�s   r�set_synthesis_voicezSSIPClient.set_synthesis_voice s��	
�
�
����u�.?��Grc�d�t|t�sJ�|jjd|d|�y)a;Set the amount of context when resuming a paused message.

        Arguments:
          value -- a positive or negative value meaning how many chunks of data
            after or before the pause should be read when resume() is executed.
          scope -- see the documentation of this class.
            
        r��
PAUSE_CONTEXTNr�r�s   r�set_pause_contextzSSIPClient.set_pause_context*s,���%��%�%�%��
�
����u�o�u�Erc��t|t�sJ�|dk(rd}nd}|jjdtj
d|�y)aSwitch debugging on and off. When switched on,
        debugging files will be created in the chosen destination
        (see set_debug_destination()) for Speech Dispatcher and all
        its running modules. All logging information will then be
        written into these files with maximal verbosity until switched
        off. You should always first call set_debug_destination.

        The intended use of this functionality is to switch debugging
        on for a period of time while the user will repeat the behavior
        and then send the logs to the appropriate bug-reporting place.

        Arguments:
          val -- a boolean value determining whether debugging
                 is switched on or off
          scope -- see the documentation of this class.
        
        T�ON�OFFr��DEBUGN)r��boolrr�r`r�)r$�valrMs   r�	set_debugzSSIPClient.set_debug6sA��$�#�t�$�$�$��$�;��H��H��
�
����u�y�y�'�8�Drc��ttt�sJ�|jj	dt
jdt�y)z�Set debug destination.

        Arguments:
          path -- path (string) to the directory where debugging
                  files will be created
          scope -- see the documentation of this class.
        
        r��DEBUG_DESTINATIONN)r�r��stringrr�r`r�)r$r�s  r�set_debug_destinationz SSIPClient.set_debug_destinationQs1���#�v�&�&�&��
�
����u�y�y�2E�s�Krc�<�|jjdd�y)z]Begin an SSIP block.

        See SSIP documentation for more details about blocks.

        �BLOCKrNrYr*s r�block_beginzSSIPClient.block_begin^s��	
�
�
�����1rc�<�|jjdd�y)z]Close an SSIP block.

        See SSIP documentation for more details about blocks.

        r�rNrYr*s r�	block_endzSSIPClient.block_endfs��	
�
�
�����/rc�V�t|d�r|jj�|`yy)z*Close the connection to Speech Dispatcher.rN)�hasattrrr�r*s rr�zSSIPClient.closens&���4��!��J�J�����
�"r)�default�unknownNNNNNNr:)2r
rrrrrr�r#rrrr(rrIrNrRrVrZr]r�r�r
rbrrrhrrrurwrzr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�r��s����*�L�.��L�5�:��7�JN��@D�M;�^�$P� �6�*2�X
I�J�"%�ND�
,�
:�!�:�:�1����/� �*�*�0�!�:�:�1��
5�4,1�:�:�	D��-2�J�J�E��&+�Z�Z�>��,1�:�:�D�%*�J�J�=��',�j�j�?��,1�:�:�
D��).�
�
�E� /4�j�j�G�&+�Z�Z�C�&05�z�z�H�.3�Z�Z�
F�E�6L�2�0�rr�c���eZdZdZd�fd�	Zejfd�Zejf�fd�	Z	ejf�fd�	Z
ejf�fd�	Z�xZS)�Clienta0A DEPRECATED backwards-compatible API.

    This Class is provided only for backwards compatibility with the previous
    unofficial API.  It will be removed in future versions.  Please use either
    'SSIPClient' or 'Speaker' interface instead.  As deprecated, the API is no
    longer documented.

    c�B��|xs|xsd}tt|�
|fi|��y)N�python)r"r�r#)r$ra�clientr'r(s    �rr#zClient.__init__~s&����)�v�)���
�f�d�$�T�4�V�4rc�H�|j|�|j|�yr�)rIrR)r$r�rHs   r�sayz
Client.say�s�����(�#��
�
�4�rc�N��|j|�tt|�|�yr�)rIr"r�rV)r$rVrHr(s   �rrVzClient.char�s ������(�#�
�f�d� ��&rc�N��|j|�tt|�|�yr�)rIr"r�rZ)r$rZrHr(s   �rrZz
Client.key�s ������(�#�
�f�d���$rc�N��|j|�tt|�|�yr�)rIr"r�r])r$r]rHr(s   �rr]zClient.sound_icon�s ������(�#�
�f�d�&�z�2rr:)
r
rrrr#r�r�r�r�rVrZr]r;r<s@rr�r�usL����5�"*�!1�!1��#+�-�-�'�!)�
�
�%�/7�m�m�3�3rr�c��eZdZdZy)�Speakera�Extended Speech Dispatcher Interface.

    This class provides an extended intercace to Speech Dispatcher
    functionality and tries to hide most of the lower level details of SSIP
    (such as a more sophisticated handling of blocks and priorities and
    advanced event notifications) under a more convenient API.
    
    Please note that the API is not yet stabilized and thus is subject to
    change!  Please contact the authors if you plan using it and/or if you have
    any suggestions.

    Well, in fact this class is currently not implemented at all.  It is just a
    draft.  The intention is to hide the SSIP details and provide a generic
    interface practical for screen readers.
    
    Nrrrrr�r��s��rr�c��eZdZdZdZ	dZy)�ConnectionMethodz�Constants describing the possible methods of connection to server.

    Retained for backwards compatibility but DEPRECATED. See CommunicationMethod.rWrXNrYrrrr�r��s��U� �K�;��K�9rr�)rrcr�r�r4�time�tempfilero�dummy_threading�r�objectrr@rrr>rLrQrTrVr]r�r�r�r�r�r�r�r�r�rrr�<module>r�s�� �3�2�2�(���)�6�)�.F�	�F�,�Y�,�\
�	�
� �(���%��1��1�:�&�:�l"�v�l"�\!�v�!�B
L�F�
L��v���f��&;�v�;�S
��S
�l3�Z�3�<�j��,:�v�:��U$(�'�s�C-�-C5

Zerion Mini Shell 1.0