Mini Shell

Direktori : /lib64/python3.6/site-packages/speechd/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/speechd/__pycache__/client.cpython-36.opt-1.pyc

3

�7Zų�
@s�dZddlZddlZddlZddlZddlZddlZyddlZWnddlZYnXddl	m
Z
Gdd�de�ZGdd�de
�ZGd	d
�d
e�ZGdd�de
�ZGd
d�de�ZGdd�de�ZGdd�de
�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd �d e�ZGd!d"�d"e�ZGd#d$�d$e�ZGd%d&�d&e�ZGd'd(�d(e�ZdS))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@s(eZdZdZdZdZdZdZdZdZ	dS)	�CallbackTypez5Constants describing the available types of callbacksZindex_marksZbegin�end�cancel�pause�resumeN)
�__name__�
__module__�__qualname__�__doc__�
INDEX_MARK�BEGIN�END�CANCEL�PAUSE�RESUME�rr�/usr/lib64/python3.6/client.pyr%src@seZdZdZdS)�	SSIPErrorz;Common base class for exceptions during SSIP communication.N)r	r
rrrrrrr<srcsNeZdZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
�ZS)�SSIPCommunicationErrorz?Exception raised when trying to operate on a closed connection.Ncs"||_||_tt|�jf|�dS)N)�_original_exception�_description�superr�__init__)�self�description�original_exception�kwargs)�	__class__rrrDszSSIPCommunicationError.__init__cCs|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)rrrrrIsz)SSIPCommunicationError.original_exceptioncCs
||_dS)zXSet an additional exception
        
        See method additional_exception().
        N)�_additional_exception)rZ	exceptionrrr�set_additional_exceptionQsz/SSIPCommunicationError.set_additional_exceptioncCs|jS)z�Return an additional exception
        
        Additional exceptions araise from failed attempts to resolve
        the former problem)r )rrrr�additional_exceptionXsz+SSIPCommunicationError.additional_exceptioncCs|jS)zReturn error description)r)rrrrr_sz"SSIPCommunicationError.descriptioncCs\g}|j�r|j|j��|jr6|jdt|j���|jrR|jdt|j���dj|�S)NzOriginal error: zAdditional error: �
)r�appendr�strr"�join)rZmsgsrrr�__str__cszSSIPCommunicationError.__str__)NN)r	r
rrr rrr!r"rr'�
__classcell__rr)rrr?src@s$eZdZdd�Zdd�Zdd�ZdS)�SSIPResponseErrorcCs*tj|d||f�||_||_||_dS)Nz%s: %s)�	Exceptionr�_code�_msg�_data)r�code�msg�datarrrrnszSSIPResponseError.__init__cCs|jS)z8Return the server response error code as integer number.)r+)rrrrr.tszSSIPResponseError.codecCs|jS)z/Return server response error message as string.)r,)rrrrr/xszSSIPResponseError.msgN)r	r
rrr.r/rrrrr)msr)c@seZdZdZdd�ZdS)�SSIPCommandErrorz9Exception raised on error response after sending command.cCs|jS)z7Return the command string which resulted in this error.)r-)rrrr�command�szSSIPCommandError.commandN)r	r
rrr2rrrrr1}sr1c@seZdZdZdd�ZdS)�
SSIPDataErrorz6Exception raised on error response after sending data.cCs|jS)z-Return the data which resulted in this error.)r-)rrrrr0�szSSIPDataError.dataN)r	r
rrr0rrrrr3�sr3c@seZdZdZdS)�
SpawnErrorz&Indicates failure in server autospawn.N)r	r
rrrrrrr4�sr4c@seZdZdZdZdZdS)�CommunicationMethodzBConstants describing the possible methods of connection to server.�unix_socket�inet_socketN)r	r
rr�UNIX_SOCKET�INET_SOCKETrrrrr5�sr5c@s�eZdZdZdZdZdZeeeZeeeZeeZ	eeZ
ejej
ejejejejd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�_SSIP_Connectionz/Implemantation of low level SSIP communication.s
�.s..)i�i�i�i�i�i�cCs�|tjkrtj}|}n(|tjkr6tj}tj|�|f}ntd��y tj|tj�|_	|j	j
|�Wn4tjk
r�}ztd||d��WYdd}~XnXd|_
g|_d|_tjd�|_tj|jidd�|_|jj�dS)	z�Init connection: open the socket to server,
        initialize buffers, launch a communication handling
        thread.
        z Unsupported communication methodzCan't open socket using method )rN�rz SSIP client communication thread)�targetr�name)r5r8�socketZAF_UNIXr9ZAF_INETZ
gethostbyname�
ValueErrorZSOCK_STREAM�_socketZconnect�errorr�_buffer�_com_buffer�	_callback�	threadingZ	Semaphore�_ssip_reply_semaphoreZThread�_communication�_communication_thread�start)r�communication_method�socket_path�host�portZ
socket_familyZsocket_connect_argsZexrrrr�s*



z_SSIP_Connection.__init__cCsBy|jjtj�Wntjk
r(YnX|jj�|jj�dS)z>Close the server connection, destroy the communication thread.N)rAZshutdownr?Z	SHUT_RDWRrB�closerIr&)rrrrrO�s
z_SSIP_Connection.closec
Cs�x�y|j�\}}}Wntk
r0tj�YnX|ddkr\|jj|||f�|jj�q|jdk	r|j	|}|t
jkr�d|di}ni}tt
|dd��\}}|j|||f|�qWdS)a,Handle incomming socket communication.

        Listens for all incomming 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�NZ
index_mark�)�
_recv_message�IOError�sys�exitrDr$rG�releaserE�_CALLBACK_TYPE_MAPrr
�map�int)rr.r/r0�typer�msg_id�	client_idrrrrH�s 




z_SSIP_Connection._communicationc	Cs�|jj|j�}xZ|dkrhy|jjd�}Wnt�YnXt|�dkrJt�|j|7_|jj|j�}qW|jd|�}|j|t|j�d�|_|jd�S)zuRead one whole line from the socket.

        Blocks until the line delimiter ('_NEWLINE') is read.
        
        rirNzutf-8���)rC�find�_NEWLINErAZrecvrT�len�decode)rZpointer�d�linerrr�	_readline�s

z_SSIP_Connection._readlinecCsfg}d}xX|j�}|dd�|d|dd�}}}|dkrT|}t|�|t|�fS|j|�q
WdS)zTRead server response or a callback
        and return the triplet (code, msg, data).N��� )rerZ�tupler$)rr0�crdr.�sep�textr/rrrrSs$z_SSIP_Connection._recv_messagecCs.|jj�st�|jj�|jd}|jd=|S)zdRead server response from the communication thread
        and return the triplet (code, msg, data).r)rIZisAliverrG�acquirerD)rZresponserrr�_recv_response s


z_SSIP_Connection._recv_responsecGs�dj|fttt|���}y|jj|jd�|j�Wntj	k
rTt
d��YnX|j�\}}}|ddkr|t|||��|||fS)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.
        
        rhzutf-8z"Speech Dispatcher connection lost.rPrR)
r&rirYr%rA�send�encoder`r?rBrrnr1)rr2�args�cmdr.r/r0rrr�send_command-sz_SSIP_Connection.send_commandcCs�|jd�}|j|j�r2t|j�}|j||d�}|j|j|j�}y|jj	||j
�Wntjk
rvt
d��YnX|j�\}}}|ddkr�t|||��|||fS)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.
        
        zutf-8Nz"Speech Dispatcher connection lost.rPrR)rp�
startswith�_END_OF_DATA_MARKERra�_END_OF_DATA_MARKER_ESCAPED�replace�_RAW_DOTLINE�_ESCAPED_DOTLINErAro�_END_OF_DATAr?rBrrnr3)rr0�lr.r/Z
response_datarrr�	send_dataLs

z_SSIP_Connection.send_datacCs
||_dS)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)rE)r�callbackrrr�set_callbackmsz_SSIP_Connection.set_callbackN)r	r
rrr`rurvrzZ_END_OF_DATA_ESCAPEDrxryrr
rrrrrrXrrOrHrerSrnrsr|r~rrrrr:�s.
!$
!r:c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�_CallbackHandlerz(Internal object which handles callbacks.cCs||_i|_tj�|_dS)N)�
_client_id�
_callbacksrFZLock�_lock)rr]rrrr�sz_CallbackHandler.__init__cKs�||jkrdS|jj�z`y|j|\}}Wntk
r@Yn6X|dksR||kr^||f|�|tjtjfkrv|j|=Wd|jj�XdS)N)	r�r�rmr��KeyErrorrrrrW)rr\r]r[rr}�event_typesrrr�__call__�s

z_CallbackHandler.__call__c
Cs.|jj�z||f|j|<Wd|jj�XdS)N)r�rmr�rW)rr\r}r�rrr�add_callback�s
z_CallbackHandler.add_callbackN)r	r
rrrr�r�rrrrr�src@seZdZdZdZdZdS)�Scopez�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	r
rr�SELF�ALLrrrrr��sr�c@s$eZdZdZdZdZdZdZdZdS)�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.
    
    Z	importantrl�messageZnotificationZprogressN)	r	r
rrZ	IMPORTANT�TEXT�MESSAGE�NOTIFICATIONZPROGRESSrrrrr��sr�c@seZdZdZdZdZdZdS)�PunctuationModezkConstants for selecting a punctuation mode.

    The mode determines which characters should be read.

    r�ZnoneZsomeN)r	r
rrr�ZNONEZSOMErrrrr��s
r�c@seZdZdZdZdZdS)�DataModezWConstants specifying the type of data contained within messages
    to be spoken.

    rlZssmlN)r	r
rrr��SSMLrrrrr��sr�c@s�eZdZdZdZdZdZdVdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdWdd�Zdd�Zdd�Zdd�Zejfd d!�Zejfd"d#�Zejfd$d%�Zejfd&d'�Zd(d)�Zd*d+�Zejfd,d-�Zd.d/�Zejfd0d1�Zd2d3�Zejfd4d5�Zd6d7�Z ejfd8d9�Z!d:d;�Z"ejfd<d=�Z#d>d?�Z$ejfd@dA�Z%ejfdBdC�Z&ejfdDdE�Z'ejfdFdG�Z(ejfdHdI�Z)ejfdJdK�Z*dLdM�Z+dNdO�Z,dPdQ�Z-dRdS�Z.dTdU�Z/dS)X�
SSIPClienta�Basic 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.

    z	127.0.0.1i�zspeech-dispatcher/speechd.sock�default�unknownNc

Cstjjd�}
tjjdtjjdtjj|
d���}tjj||j�}tj||j	|j
d�}
|p`tjjd�}|rx|
j|j|��n~tjjd�}yt
tjjd��}Wnd	}YnXtjjd
�}|r�||
d<|r�||
d<n|r�||
d<|	r�|	|
d
<n|r�||
d
<|j|
|�|j|||�d	S)aZInitialize 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
            acces 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.
        �~ZXDG_RUNTIME_DIRZXDG_CACHE_HOMEz.cache)rKrLrMrNZSPEECHD_ADDRESSZSPEECHD_HOSTZSPEECHD_PORTNZSPEECHD_SOCKET�methodrNrL)�os�path�
expanduser�environ�getr&�DEFAULT_SOCKET_PATHr5r8�DEFAULT_HOST�DEFAULT_PORT�update�"_connection_arguments_from_addressrZ�_connect_with_autospawn�_initialize_connection)rr>�	component�user�address�	autospawnrMrNr�rL�_homeZ_runtime_dirZ
_sock_path�connection_argsZ_addressZenv_speechd_hostZenv_speechd_portZenv_speechd_socket_pathrrrr�s8'"



zSSIPClient.__init__cCs�ytf|�|_Wnztk
r�}z^|dkrxy|j|�Wn0tk
rh}z|j|�|�WYdd}~XnXtf|�|_n�WYdd}~XnXdS)z2Establish new connection (and/or autospawn server)FN)r:�_connr�
_server_spawnr4r!)rr�r�ZceZserrrr�Cs
z"SSIPClient._connect_with_autospawnc	Cs�d|||f}|jjdtjd|�|jjddd�\}}}t|d�|_t|j�|_|jj|j�x8t	j
t	jt	jt	j
t	jt	jfD]}|jjddd	|d
�q~WdS)zIInitialize connection -- Set client name, get id, register callbacks etc.z%s:%s:%s�SETZCLIENT_NAMEZHISTORY�GETZ	CLIENT_IDrrr��onN)r�rsr�r�rZr�r�_callback_handlerr~rr
rrrrr)	rr�r>r�Z	full_namer.r/r0Zeventrrrr�Usz!SSIPClient._initialize_connectioncCs�i}|jd�}y|d}Wntd��YnX||d<|tjkrjy|d|d<Wq�tk
rfYq�Xnd|tjkr�y |d|d<t|d�|d	<Wq�tk
r�td
��Yq�tk
r�Yq�Xntd��|S)z^Parse a Speech Dispatcher address line and return a dictionary
        of connection arguments�:rzWrong format of server addressrKrrLrMrRrNz<Third parameter of inet_socket address must be a port numberz(Unknown communication method in address.)	�splitZSSIPCommunicationErrrorr5r8�
IndexErrorr9rZr@r)rr�r�Zaddress_params�_methodrrrr�es,


z-SSIPClient._connection_arguments_from_addresscCs|j�dS)zClose the connectionN)rO)rrrr�__del__�szSSIPClient.__del__c
Cs.|ddkrztj|d|d�}dd�|D�}d}x*|D]"}|jd�sN|d	kr8||d<d
}q8W|sztd|dt|�f��tjjtj	��rg}x8|j
�D],\}}|dkr�|d|jd
d�t|�g7}q�Wtj
tj	dg|dtjtjd�}	|	j�\}
}|	j�}|dk�rtd|f��|	jStdtj	f��dS)z/Attempts to spawn the speech-dispatcher server.rKr7rMrNcSsg|]}|dd�qS)rgrr)�.0Zaddrinforrr�
<listcomp>�sz,SSIPClient._server_spawn.<locals>.<listcomp>Fz127.z::1Tz�Can't start server automatically (autospawn), requested address %s resolves on %s which seems to be a remote host. You must start the server manually or choose another connection address.z--�_�-z--spawnN)�stdin�stdout�stderrrz4Server refused to autospawn, stating this reason: %sz-Can't find Speech Dispatcher spawn command %s)rM)r?Zgetaddrinfortr4r%r�r��existsrZ
SPD_SPAWN_CMD�itemsrw�
subprocess�Popen�PIPEZcommunicate�wait�pid)
rr�Z	addrinfosZip_addressesZ	localhostZipZconnection_paramsZparam�valueZserverZstdout_replyZstderr_replyZretcoderrrr��s8


 
zSSIPClient._server_spawncCs|jjdtjd|�dS)z�Set the priority category for the following messages.

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

        r�ZPRIORITYN)r�rsr�r�)r�priorityrrr�set_priority�s
zSSIPClient.set_prioritycCsD|tjkrd}n|tjkr d}ntd|��|jjdtjd|�dS)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�Z	SSML_MODEN)r�r�r�r@r�rsr�r�)rr��ssip_valrrr�
set_data_mode�s

zSSIPClient.set_data_modecCs@|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.

        ZSPEAKrRr)r�rsr|rZr�r�)rrlr}r��resultr\rrr�speak�szSSIPClient.speakcCs|jjd|jdd��dS)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.

        ZCHARrhZspaceN)r�rsrw)r�charrrrr��szSSIPClient.charcCs|jjd|�dS)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.

        ZKEYN)r�rs)r�keyrrrr��s
zSSIPClient.keycCs|jjd|�dS)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.

        Z
SOUND_ICONN)r�rs)r�
sound_iconrrrr�
s
zSSIPClient.sound_iconcCs|jjd|�dS)z�Immediately stop speaking and discard messages in queues.

        Arguments:
          scope -- see the documentation of this class.
            
        rN)r�rs)r�scoperrrrszSSIPClient.cancelcCs|jjd|�dS)z�Immediately stop speaking the currently spoken message.

        Arguments:
          scope -- see the documentation of this class.
        
        ZSTOPN)r�rs)rr�rrr�stop szSSIPClient.stopcCs|jjd|�dS)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.
        
        rN)r�rs)rr�rrrr)szSSIPClient.pausecCs|jjd|�dS)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.
        
        rN)r�rs)rr�rrrr6szSSIPClient.resumecCs|jjdd�\}}}|S)z@Return names of all active output modules as a tuple of strings.�LISTZOUTPUT_MODULES)r�rs)rr.r/r0rrr�list_output_modulesCszSSIPClient.list_output_modulescsLy|jjdd�\}}}Wntk
r,fSXdd��t�fdd�|D��S)a"Return names of all available voices for the current output module.

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

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

        r�ZSYNTHESIS_VOICEScSs(t|jdd��\}}}||pd|p$dfS)Nrhrf)ri�rsplit)�itemr>ZlangZdialectrrrr�Usz/SSIPClient.list_synthesis_voices.<locals>.splitcsg|]}�|��qSrr)r�r�)r�rrr�Xsz4SSIPClient.list_synthesis_voices.<locals>.<listcomp>)r�rsr1ri)rr.r/r0r)r�r�list_synthesis_voicesHs	z SSIPClient.list_synthesis_voicescCs|jjd|d|�dS)z�Switch to a particular language for further speech commands.

        Arguments:
          language -- two letter language code according to RFC 1766 as string.
          scope -- see the documentation of this class.
            
        r��LANGUAGEN)r�rs)rZlanguager�rrr�set_languageZs	zSSIPClient.set_languagecCs$|jjdd�\}}}|r |dSdS)zGet the current language.r�r�rN)r�rs)rr.r/r0rrr�get_languageeszSSIPClient.get_languagecCs|jjd|d|�dS)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_MODULEN)r�rs)rr>r�rrr�set_output_modulelszSSIPClient.set_output_modulecCs$|jjdd�\}}}|r |dSdS)zGet the current output module.r�r�rN)r�rs)rr.r/r0rrr�get_output_modulevszSSIPClient.get_output_modulecCs|jjd|d|�dS)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��PITCHN)r�rs)rr�r�rrr�	set_pitch}szSSIPClient.set_pitchcCs$|jjdd�\}}}|r |dSdS)zGet the current pitch.r�r�rN)r�rs)rr.r/r0rrr�	get_pitch�szSSIPClient.get_pitchcCs|jjd|d|�dS)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��RATEN)r�rs)rr�r�rrr�set_rate�szSSIPClient.set_ratecCs$|jjdd�\}}}|r |dSdS)z$Get the current speech rate (speed).r�r�rN)r�rs)rr.r/r0rrr�get_rate�szSSIPClient.get_ratecCs|jjd|d|�dS)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��VOLUMEN)r�rs)rr�r�rrr�
set_volume�szSSIPClient.set_volumecCs$|jjdd�\}}}|r |dSdS)zGet the speech volume.r�r�rN)r�rs)rr.r/r0rrr�
get_volume�szSSIPClient.get_volumecCs|jjd|d|�dS)z�Set the punctuation pronounciation level.

        Arguments:
          value -- one of the 'PunctuationMode' constants.
          scope -- see the documentation of this class.
            
        r�ZPUNCTUATIONN)r�rs)rr�r�rrr�set_punctuation�s
zSSIPClient.set_punctuationcCs2|dkr|jjd|dd�n|jjd|dd�dS)a-Toogle the spelling mode or on off.

        Arguments:
          value -- if 'True', all incomming messages will be spelled
            instead of being read as normal words. 'False' switches
            this behavior off.
          scope -- see the documentation of this class.
            
        Tr�ZSPELLINGr�r�N)r�rs)rr�r�rrr�set_spelling�szSSIPClient.set_spellingcCs|jjd|d|�dS)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 syntetic voice and 'icon' means that the capital-letter icon
            will be prepended before each capital letter.
          scope -- see the documentation of this class.
            
        r�ZCAP_LET_RECOGNN)r�rs)rr�r�rrr�set_cap_let_recogn�szSSIPClient.set_cap_let_recogncCs|jjd|d|�dS)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.
            
        r�Z
VOICE_TYPEN)r�rs)rr�r�rrr�	set_voice�szSSIPClient.set_voicecCs|jjd|d|�dS)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�ZSYNTHESIS_VOICEN)r�rs)rr�r�rrr�set_synthesis_voice�szSSIPClient.set_synthesis_voicecCs|jjd|d|�dS)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�Z
PAUSE_CONTEXTN)r�rs)rr�r�rrr�set_pause_contexts
zSSIPClient.set_pause_contextcCs*|dkrd}nd}|jjdtjd|�dS)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 debuging
        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.
        
        TZONZOFFr��DEBUGN)r�rsr�r�)r�valr�rrr�	set_debugszSSIPClient.set_debugcCs|jjdtjdt�dS)z�Set debug destination.

        Arguments:
          path -- path (string) to the directory where debuging
                  files will be created
          scope -- see the documentation of this class.
        
        r�ZDEBUG_DESTINATIONN)r�rsr�r�r�)rr�rrr�set_debug_destination)sz SSIPClient.set_debug_destinationcCs|jjdd�dS)z]Begin an SSIP block.

        See SSIP documentation for more details about blocks.

        �BLOCKrN)r�rs)rrrr�block_begin6szSSIPClient.block_begincCs|jjdd�dS)z]Close an SSIP block.

        See SSIP documentation for more details about blocks.

        r�rN)r�rs)rrrr�	block_end>szSSIPClient.block_endcCst|d�r|jj�|`dS)z*Close the connection to Speech Dispatcher.r�N)�hasattrr�rO)rrrrrOFs

zSSIPClient.close)r�r�NNNNNN)NN)0r	r
rrr�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�rr�rrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rOrrrrr��sZ
L)
'

	





r�csfeZdZdZd
�fdd�	Zejfdd�Zejf�fdd�	Z	ejf�fd	d
�	Z
ejf�fdd�	Z�ZS)�Clienta0A DEPRECATED backwards-compatible API.

    This Class is provided only for backwards compatibility with the prevoius
    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.

    Ncs$|p
|p
d}tt|�j|f|�dS)N�python)rr�r)rr>Zclientr)rrrrVszClient.__init__cCs|j|�|j|�dS)N)r�r�)rrlr�rrr�sayZs
z
Client.saycs|j|�tt|�j|�dS)N)r�rr�r�)rr�r�)rrrr�^s
zClient.charcs|j|�tt|�j|�dS)N)r�rr�r�)rr�r�)rrrr�bs
z
Client.keycs|j|�tt|�j|�dS)N)r�rr�r�)rr�r�)rrrr�fs
zClient.sound_icon)NN)
r	r
rrrr�r�r�r�r�r�r�r(rr)rrr�Msr�c@seZdZdZdS)�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.
    
    N)r	r
rrrrrrr�ksr�c@seZdZdZdZdZdS)�ConnectionMethodz�Constants describing the possible methods of connection to server.

    Retained for backwards compatibility but DEPRECATED. See CommunicationMethod.r6r7N)r	r
rrr8r9rrrrr��sr�)rr?rUr�r�ZtimeZtempfilerFZdummy_threading�r�objectrr*rrr)r1r3r4r5r:rr�r�r�r�r�r�r�r�rrrr�<module>s:0.m!
u