+
    0g  c                   s   R t ^ RIt^ RIt^ RIt^ RIt^ RIt ^ RIt^RIH	t	  ! R R]
4      t ! R R]4      t ! R R]4      t ! R	 R
]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]
4      t ! R R]
4      t ! R R]
4      t ! R R]
4      t ! R R]
4      t ! R R]
4      t ! R R]
4      t ! R R ]
4      t ! R! R"]4      t ! R# R$]4      t ! R% R&]
4      tR#    ^ RIt L; i)'zPython 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<    ] tR t^$tRtRt Rt Rt Rt Rt	 Rt
RtR	# )
CallbackTypez5Constants describing the available types of callbacksZindex_marksZbeginZendcancelpauseresume N)__name__
__module____qualname____firstlineno____doc__
INDEX_MARKBEGINENDCANCELPAUSERESUME__static_attributes__r       5/usr/lib64/python3.14/site-packages/speechd/client.pyr   r   $   sE    ?J E&
C;F E4F)r   r   c                   s    ] tR t^;tRtRtR# )	SSIPErrorz;Common base class for exceptions during SSIP communication.r   Nr   r   r   r	   r
   r   r   r   r   r   r   ;   s    Er   r   c                   s\   a a ] tR t^>t oRtRtR
V 3R lltR tR tR t	R t
R tR	tVtV ;t# )SSIPCommunicationErrorz?Exception raised when trying to operate on a closed connection.Nc                sH   < W n         Wn        \        \        V `  ! R/ VB  R # )Nr   )_original_exception_descriptionsuperr   __init__)selfdescriptionoriginal_exceptionkwargs	__class__   &&&,r   r   ZSSIPCommunicationError.__init__C   s!    #5 'i'1&1r   c                    V P                   # )zReturn 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      &r   r   Z)SSIPCommunicationError.original_exceptionH   s     '''r   c                    Wn         R# )z@Set an additional exception

See method additional_exception().
N_additional_exception)r   Z	exception   &&r   set_additional_exceptionZ/SSIPCommunicationError.set_additional_exceptionP   s
    
 &/"r   c                r!   )zoReturn an additional exception

Additional exceptions araise from failed attempts to resolve
the former problemr%   r"   r#   r   additional_exceptionZ+SSIPCommunicationError.additional_exceptionW   s    
 )))r   c                r!   )zReturn error description)r   r"   r#   r   r   Z"SSIPCommunicationError.description^   s       r   c                s   . pV P                  4       '       d    VP                  V P                  4       4       V P                  '       d0   VP                  R \        V P                  4       4      ,           4       V P                  '       d0   VP                  R\        V P	                  4       4      ,           4       RP                  V4      # )zOriginal error: zAdditional error: Z
)r   appendr   strr)   join)r   Zmsgs   & r   __str__ZSSIPCommunicationError.__str__b   s    KK((*+"""KK*S1H1H1J-KKL$$$KK,s43L3L3N/OOPyyr   )r&   r   r   NN)r   r   r   r	   r
   r&   r   r   r(   r)   r   r.   r   __classdictcell____classcell__r   __classdict__   @@r   r   r   >   s1     I 2
(/*! r   r   c                   s2   a  ] tR t^lt o R tR tR tRtV tR# )SSIPResponseErrorc                sb    \         P                  W: R V: 24       Wn        W n        W0n        R# )z: N)	Exceptionr   _code_msg_datar   codemsgdata   &&&&r   r   ZSSIPResponseError.__init__m   s&    4T3!78
	
r   c                r!   )z8Return the server response error code as integer number.)r7   r"   r#   r   r;   ZSSIPResponseError.codes       zzr   c                r!   )z/Return server response error message as string.)r8   r"   r#   r   r<   ZSSIPResponseError.msgw   s    yyr   )r7   r9   r8   N)	r   r   r   r	   r   r;   r<   r   r0   r3      @r   r5   r5   l   s      r   r5   c                   s*   a  ] tR t^|t o RtR tRtV tR# )SSIPCommandErrorz9Exception raised on error response after sending command.c                r!   )z7Return the command string which resulted in this error.r9   r"   r#   r   commandZSSIPCommandError.command   r?   r   r   N)r   r   r   r	   r
   rD   r   r0   r@   rA   r   rB   rB   |   s     C r   rB   c                   s*   a  ] tR t^t o RtR tRtV tR# )SSIPDataErrorz6Exception raised on error response after sending data.c                r!   )z-Return the data which resulted in this error.rC   r"   r#   r   r=   ZSSIPDataError.data   r?   r   r   N)r   r   r   r	   r
   r=   r   r0   r@   rA   r   rE   rE      s     @ r   rE   c                   s    ] tR t^tRtRtR# )
SpawnErrorz&Indicates failure in server autospawn.r   Nr   r   r   r   rF   rF      s    0r   rF   c                   s$    ] tR t^tRtRt RtRtR# )CommunicationMethodzBConstants describing the possible methods of connection to server.unix_socketinet_socketr   Nr   r   r   r	   r
   UNIX_SOCKETINET_SOCKETr   r   r   r   rG   rG      s    LK;K9r   rG   c                   s^  a  ] tR t^t o RtRtRtRt]],           ],           t]],           ],           t	]],           t
]],           tR]P                  R]P                  R]P                  R]P                   R	]P"                  R
]P$                  /tR tR tR tR tR tR tR tR tR tRtV tR# )_SSIP_Connectionz/Implementation of low level SSIP communication.s   
s   .s   ..i  i  i  i  i  i  c                s   V\         P                  8X  d   \        P                  pTpM[V\         P                  8X  d<   V'       d	   V'       g   Q h\        P
                  p\        P                  ! V4      V3pM\        R4      h \        P                  ! V\        P                  4      V n	        V P                  P                  V4       RT n        . T n        RT n        \         P"                  ! ^ 4      T n        \         P&                  ! T P(                  / RRR7      T n        T P*                  P-                  4        R#   \        P                   d   p\        RT,           TR7      hRp?ii ; i)	zhInit connection: open the socket to server,
initialize buffers, launch a communication handling
thread.
z Unsupported communication methodzCan't open socket using method )r   Nr   z SSIP client communication threadT)Ztargetr   nameZdaemon)rG   rK   socketZAF_UNIXrL   ZAF_INETZgethostbyname
ValueErrorZSOCK_STREAM_socketZconnecterrorr   _buffer_com_buffer	_callback	threadingZ	Semaphore_ssip_reply_semaphoreZThread_communication_communication_threadZstart)r   communication_methodsocket_pathhostportZsocket_familyZsocket_connect_argsZexs   &&&&&   r   r   Z_SSIP_Connection.__init__   s2     #6#B#BB"NNM"-!%8%D%DDD ="NNM#)#7#7#=t"D?@@	B!==8J8JKDLLL  !45 %.%8%8%;"  (;(;B&H(,. 	" 	""((* || 	B()J+?*@>@B B	Bs   AD? ?E-E((E-c                s     V P                   P                  \        P                  4       V P                   P                  4        V P                  P                  4        R#   \        P                   d     LMi ; i)z>Close the server connection, destroy the communication thread.N)rQ   ZshutdownrO   Z	SHUT_RDWRrR   closerY   r,   r"   r#   r   r^   Z_SSIP_Connection.close   s[    	LL!!&"2"23 	""'')	 || 		s   )A! !A98A9c                s     V P                  4       w  rpT^d,          ^8w  d:   T P                  P                  YT34       T P                  P                  4        K\  T P                  f   Kl  T P                  T,          pT\        P                  8X  d   RT^,          /pM/ p\        \        TR,          4      w  rgT P                  ! YgT3/ TB  K    \         d     R# i ; i)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.NZ
index_mark:Ni   N)_recv_messageIOErrorrT   r*   rW   releaserU   _CALLBACK_TYPE_MAPr   r   mapint)r   r;   r<   r=   typer   msg_id	client_id   &       r   rX   Z_SSIP_Connection._communication   s     "&"4"4"64 SyA~  ''D(9:**224~~)..t4<222*DG4FF$'T"X$6!v$A&A#  s   C C! C!c                s   V P                   P                  V P                  4      pVR8X  ds    V P                  P	                  R4      p\        T4      ^ 8X  d   \
        hT ;P                   T,          un         T P                   P                  T P                  4      pKy  V P                   RV pV P                   V\        V P                  4      ,           R V n         VP                  R4      #    \
        h; i)z]Read one whole line from the socket.

Blocks until the line delimiter ('_NEWLINE') is read.

i   Nutf-8i)rS   Zfind_NEWLINErQ   Zrecvr`   lenZdecode)r   ZpointerZdline   &   r   	_readlineZ_SSIP_Connection._readline   s     ,,##DMM2mLL%%d+ 1v{LLALll''6G||HW%||GC,>$>$?@{{7##s   C- -C5c                sT   . pRp V P                  4       p\        V4      ^8  g   Q R4       hVR,          V^,          VR,          repVP                  4       '       d   Ve   WB8X  d   VR9   g   Q R4       hVR8X  d   Tp\        V4      V\	        V4      3# TpVP                  V4       K  )zLRead server response or a callback
and return the triplet (code, msg, data).Nz$Malformed data received from server!:Ni   N:i   NN )-ro   )rn   rk   Zisalnumrd   tupler*   )r   r=   Zcrl   r;   Zseptextr<   rh   r   r_   Z_SSIP_Connection._recv_message  s     >>#Dt9>I#II>"2hQbtD<<>>qyDI*$M&LM %cz4y#uT{22AKKr   c                s    V P                   P                  4       '       g   \        hV P                  P	                  4        V P
                  ^ ,          pV P
                  ^  V# )z\Read server response from the communication thread
and return the triplet (code, msg, data).)rY   Zis_aliver   rW   acquirerT   )r   Zresponser-   r   _recv_responseZ_SSIP_Connection._recv_response!  sT    
 ))2244((""**,##A&Qr   c           	     s*    VR9   dL   V^ ,          \         P                  \         P                  39   g    \        V^ ,          \        4      '       g   Q hRP                  V3\        \        \        V4      4      ,           4      p V P                  P                  VP                  R4      V P                  ,           4       T P!                  4       w  rEpT^d,          ^8w  d   \#        YET4      hYET3#   \        P                   d    \        R4      hi ; i)ab  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.

ro   ri   "Speech Dispatcher connection lost.)SETr   STOP)ScopeSELFALL
isinstancerd   r,   rq   rc   r+   rQ   sendencoderj   rO   rR   r   rt   rB   )r   rD   Zargscmdr;   r<   r=   s   &&*    r   send_commandZ_SSIP_Connection.send_command.  s    " 44Aw5::uyy"99$T!Wc223 3hhzE#c4.$99:	OLLcjj1DMMAB --/49>"4c22$ || 	O()MNN	Os   ;C1 1!Dc                s   VP                  R4      pVP                  V P                  4      '       d+   \        V P                  4      pV P                  WR ,           pVP                  V P                  V P                  4      p V P                  P                  WP                  ,           4       T P                  4       w  r4pT^d,          ^8w  d   \        Y4T4      hY4T3#   \        P                   d    \        R4      hi ; i)a8  Send 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.

ri   Nru   )r}   
startswith_END_OF_DATA_MARKERrk   _END_OF_DATA_MARKER_ESCAPEDreplace_RAW_DOTLINE_ESCAPED_DOTLINErQ   r|   _END_OF_DATArO   rR   r   rt   rE   )r   r=   Zlr;   r<   Zresponse_datas   &&    r   	send_dataZ_SSIP_Connection.send_dataM  s     {{7# ??43344D,,-A33d2h>D ||D--t/D/DE	OLLd%6%667 $(#6#6#8 =9>400-'' || 	O()MNN	Os   +C   !Dc                r$   )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)rU   )r   callbackr'   r   set_callbackZ_SSIP_Connection.set_callbackn  s	    ( "r   )rS   rU   rT   rY   rQ   rW   N)r   r   r   r	   r
   rj   r   r   r   Z_END_OF_DATA_ESCAPEDr   r   r   r   r   r   r   r   r   rb   r   r^   rX   rn   r_   rt   r   r   r   r   r0   r@   rA   r   rM   rM      s     9H"'11H<L#&AAHL11L"==|66|11|//|22|11|22 +D
*!BH$(">(B" "r   rM   c                   s6   a  ] tR tRt o RtR tR tR tRtV t	R# )_CallbackHandleri  z(Internal object which handles callbacks.c                sT    Wn         / V n        \        P                  ! 4       V n        R # N)
_client_id
_callbacksrV   ZLock_lock)r   rg   r'   r   r   Z_CallbackHandler.__init__  s    #^^%
r   c                s   W P                   8w  d   R # V P                  P                  4          V P                  V,          w  rVVe   W69   d
   V! V3/ VB  V\        P
                  \        P                  39   d   V P                  V T P                  P                  4        R #   \         d     L)i ; i  T P                  P                  4        i ; ir   )	r   r   rs   r   r   r   r   ZKeyErrorra   )r   rf   rg   re   r   r   event_typess   &&&&,  r   __call__Z_CallbackHandler.__call__  s    '

	!0(,(?% &$*=T,V,L,,l.A.ABB/JJ    JJ s*   B% AB6 %B30B6 2B33B6 6Cc                s    V P                   P                  4         W#3V P                  V&   V P                   P                  4        R #   T P                   P                  4        i ; ir   )r   rs   r   ra   )r   rf   r   r   r>   r   add_callbackZ_CallbackHandler.add_callback  sI    

	!'/&=DOOF#JJ DJJ s   A A$)r   r   r   N)
r   r   r   r	   r
   r   r   r   r   r0   r@   rA   r   r   r     s     2&
!$! !r   r   c                   $    ] tR tRtRtRt RtRtR# )rx   i  zAn enumeration of valid SSIP command scopes.

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

r   allr   N)r   r   r   r	   r
   ry   rz   r   r   r   r   rx   rx     s     DL
CKr   rx   c                   s.    ] tR tRtRtRtRtRtRtRt	Rt
R	# )
Priorityi  zAn 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	importantrr   ZmessageZnotificationZprogressr   N)r   r   r   r	   r
   	IMPORTANTTEXTMESSAGENOTIFICATIONPROGRESSr   r   r   r   r   r     s"     IDG!LHr   r   c                   s0    ] tR tRtRtRt Rt Rt RtRt	R# )	PunctuationModei  zcConstants for selecting a punctuation mode.

The mode determines which characters should be read.

r   noneZsomeZmostr   N)
r   r   r   r	   r
   rz   NONESOMEMOSTr   r   r   r   r   r     s+    
 C*D6DHDr   r   c                   r   )DataModei  zOConstants specifying the type of data contained within messages
to be spoken.

rr   Zssmlr   N)r   r   r   r	   r
   r   SSMLr   r   r   r   r   r     s     DD:r   r   c                   s  a  ] tR tRt o RtRt Rt Rt R1R ltR t	R	 t
R
 tR tR tR tR tR2R ltR tR tR t]P*                  3R lt]P*                  3R lt]P*                  3R lt]P*                  3R ltR tR2R lt]P*                  3R ltR t]P*                  3R ltR t]P*                  3R lt R t!]P*                  3R lt"]P*                  3R  lt#R! t$]P*                  3R" lt%R# t&]P*                  3R$ lt'R% t(]P*                  3R& lt)]P*                  3R' lt*]P*                  3R( lt+]P*                  3R) lt,]P*                  3R* lt-R+ t.R, t/R- t0R. t1R/ t2R0t3V t4R# )3
SSIPClienti  a  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.

Here is a simple example:

from speechd import client
c = client.SSIPClient("mytest")
c.speak("hello, world!")
z	127.0.0.1i  zspeech-dispatcher/speechd.sockNc
           
     s   \         P                  P                  R4      p
\         P                  P	                  R\         P                  P	                  R\         P                  P                  V
R4      4      4      p\         P                  P                  WP                  4      pR\        P                  RVRV P                  RV P                  /pT;'       g     \         P                  P	                  R	4      pV'       d"   VP                  V P                  V4      4       M\         P                  P	                  R
4      p \        \         P                  P	                  R4      4      p\         P                  P	                  R4      pT'       d   YR&   T'       d   Y}R&   MT'       d   TTR&   T	'       d   YR&   MT'       d   TTR&   V P                  W4       V P                  W1V4       R#    Rp L; i)ac  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.
Z~ZXDG_RUNTIME_DIRZXDG_CACHE_HOMEz.cacherZ   r[   r\   r]   ZSPEECHD_ADDRESSZSPEECHD_HOSTZSPEECHD_PORTNZSPEECHD_SOCKETmethod)ospathZ
expanduserZenvironZgetr,   DEFAULT_SOCKET_PATHrG   rK   DEFAULT_HOSTDEFAULT_PORTZupdate"_connection_arguments_from_addressrd   _connect_with_autospawn_initialize_connection)r   rN   	componentuseraddress	autospawnr\   r]   r   r[   Z_homeZ_runtime_dirZ
_sock_pathconnection_argsZ_addressZenv_speechd_hostZenv_speechd_portZenv_speechd_socket_paths   &&&&&&&&&&        r   r   ZSSIPClient.__init__  s   N ""3'zz~~&7HXZ\ZaZaZfZfglnvZw9xyWW\\,0H0HI
13F3R3R(*!4#4#4!4#4#4 ??bjjnn->?""4#J#J8#TU
  "zz~~n=(#&rzz~~n'E#F  ')jjnn5E&F# ,2)*.'!*:'1<.(1H.$$_@##D	:#(#' s   (G/ /G5c                s     \        R/ VB V n        R#   \         d]   pTR8w  dP    T P                  T4       M&  \         d   pTP                  T4       ThRp?ii ; i\        R/ TB T n         Rp?R# h Rp?ii ; i)z2Establish new connection (and/or autospawn server)FNr   )rM   _connr   _server_spawnrF   r(   )r   r   r   ZceZses   &&&  r   r   Z"SSIPClient._connect_with_autospawnK  sz    	)<O<DJ% 	E!&&7! //3H .@@

	s:    A;A69A6AAAA65A66A;c                sh   V: RV: RV: 2pV P                   P                  R\        P                  RV4       V P                   P                  RRR4      w  rVp\	        V^ ,          4      V n        \        V P
                  4      V n        V P                   P                  V P                  4       \        P                  \        P                  \        P                  \        P                  \        P                  \        P                  3 F"  pV P                   P                  RRRVR	4       K$  	  R
# )zIInitialize connection -- Set client name, get id, register callbacks etc.:rv   ZCLIENT_NAMEZHISTORYGETZ	CLIENT_IDr   r   onN)r   r   rx   ry   rd   r   r   _callback_handlerr   r   r   r   r   r   r   r   )	r   r   rN   r   Z	full_namer;   r<   r=   Zevents	   &&&&     r   r   Z!SSIPClient._initialize_connection]  s    "&i8	

uzz=)L**11)UKP4d1g,!1$//!B

 6 67"--"(("&&"))"(("))+E JJ##E6>5$O+r   c                s   / pVP                  R4      p V^ ,          pYBR&   T\        P                  8X  d    T^,          TR&   T# T\        P
                  8X  d%    T^,          TR&   \        T^,          4      TR&   T# \        R4      h   \        R4      h; i  \         d     T# i ; i  \         d    \        R4      h\         d     T# i ; i)	zVParse a Speech Dispatcher address line and return a dictionary
of connection argumentsr   zWrong format of server addressrZ   r[   r\   r]   z<Third parameter of inet_socket address must be a port numberz(Unknown communication method in address.)splitr   rG   rK   Z
IndexErrorrL   rd   rP   )r   r   r   Zaddress_paramsZ_methods   &&   r   r   Z-SSIPClient._connection_arguments_from_addressm  s     s+	K$Q'G 3:./)5551?1B.  +777*8*;'*-nQ.?*@'  ))STT#	K()IJJ
     m,-kll  	s4   	B
 B !B, 
BB)(B),CCCc                s&    V P                  4        R# )zClose the connectionN)r^   r"   r#   r   __del__ZSSIPClient.__del__  s    

r   c                s   VR,          R8X  d   \         P                  ! VR,          VR,          4      pV Uu. uF  q3^,          ^ ,          NK  	  ppRpV F)  pVP                  R4      '       g
   VR8X  g   K#  WaR&   RpK+  	  V'       g%   \        R	VR,          : R
\	        V4      : R24      h\
        P                  ! R4      pV'       g   \        P                  p\
        P                  P                  V4      '       d   . pVP                  4        F9  w  rV	R9  g   K  VRV	P                  RR4      ,           \	        V
4      .,          pK;  	  \        P                  ! VR.V,           R\        P                  \        P                  R7      pVP!                  4       w  rVP#                  4       pV^ 8w  d   \        RV: 24      hVP$                  # \        RV,          4      hu upi )z/Attempts to spawn the speech-dispatcher server.rZ   rI   r\   r]   Fz127.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.ZSPEECHD_CMDz--Z_rp   z--spawnN)ZstdinZstdoutZstderrz2Server refused to autospawn, stating this reason: z-Can't find Speech Dispatcher spawn command %s)r\   )rO   Zgetaddrinfor   rF   r+   r   Zgetenvr    ZSPD_SPAWN_CMDr   ZexistsZitemsr   
subprocessZPopenZPIPEZcommunicateZwaitZpid)r   r   Z	addrinfosZaddrinfoZip_addressesZ	localhostZipr~   Zconnection_paramsZparamvalueZserverZstdout_replyZstderr_replyZretcodes   &&             r   r   ZSSIPClient._server_spawn  s    12mC**?6+B+:6+BDI <EE9xQKNN9LEI"==((B%K.0F+"I #  ! P__eOfOfORS_O`cd d
 ii&%%C77>># " / 5 5 7	)%$u}}S/E*Es5z)RR% !8  %%sI&67H&H,0Q[Q`Q`bF)/););)=&LkkmG!| [g!ijj::L,/1 2 2? Fs   G&c                s   V\         P                  \         P                  \         P                  \         P                  \         P
                  39   g   Q V4       hV P                  P                  R\        P                  RV4       R# )zrSet the priority category for the following messages.

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

rv   ZPRIORITYN)
r   r   r   r   r   r   r   r   rx   ry   )r   priorityr'   r   set_priorityZSSIPClient.set_priority  si     H..0@0@$MM8+@+@$--/ / 	908	9 / 	

uzz:xHr   c                s    V\         P                  8X  d   RpM*V\         P                  8X  d   RpM\        RV,          4      hV P                  P                  R\        P                  RV4       R# )zzSet 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.rv   Z	SSML_MODEN)r   r   r   rP   r   r   rx   ry   )r   r   ssip_val   && r   set_data_modeZSSIPClient.set_data_mode  s\     HMM!Hhmm#HQ  	

uzz;Ir   c                s    V P                   P                  R4       V P                   P                  V4      pV'       d6   \        V^,          ^ ,          4      pV P                  P                  WRV4       V# )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.

ZSPEAK)r   r   r   rd   r   r   )r   rr   r   r   Zresultrf   s   &&&&  r   speakZSSIPClient.speak  s\    : 	

(%%d+1&F ""//+Nr   c                s^    V P                   P                  RVP                  RR4      4       R# )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.

ZCHARro   ZspaceN)r   r   r   )r   charr'   r   r   ZSSIPClient.char  s#     	

S'(BCr   c                >    V P                   P                  RV4       R# )zSay 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.

ZKEYNr   r   )r   keyr'   r   r   ZSSIPClient.key	  s     	

s+r   c                r   )zOutput 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_ICONNr   )r   
sound_iconr'   r   r   ZSSIPClient.sound_icon  s     	

j9r   c                r   )z{Immediately stop speaking and discard messages in queues.

Arguments:
  scope -- see the documentation of this class.
    
r   Nr   r   scoper'   r   r   ZSSIPClient.cancel!  s     	

%0r   c                r   )zuImmediately stop speaking the currently spoken message.

Arguments:
  scope -- see the documentation of this class.

rw   Nr   r   r'   r   stopZSSIPClient.stop+  s     	

.r   c                r   )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.

r   Nr   r   r'   r   r   ZSSIPClient.pause4  s     	

/r   c                r   )zResume 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.

r   Nr   r   r'   r   r   ZSSIPClient.resumeA  s     	

%0r   c                sD    V P                   P                  RR4      w  rpV# )z@Return names of all active output modules as a tuple of strings.LISTZOUTPUT_MODULESr   r:   rm   r   list_output_modulesZSSIPClient.list_output_modulesN  s"    **11&:JK4r   c                s     RR.pV'       d+   VP                  V4       V'       d   VP                  V4       V P                  P                  ! V!  w  rEpR p\	        T Uu. uF
  q! T4      NK  	  up4      #   \         d    Ru # i ; iu upi )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.

r   ZSYNTHESIS_VOICESc                 sn    \        V P                  R ^4      4      w  rpY;'       g    RT;'       g    R3# )Z	N)rq   Zrsplit)itemrN   Zlangvariantrm   r   r   Z/SSIPClient.list_synthesis_voices.<locals>.splith  s3    "'D!(<"=D,,$488r   r   )r*   r   r   rB   rq   )	r   languager   rD   r;   r<   r=   r   r   s	   &&&      r   list_synthesis_voicesZ SSIPClient.list_synthesis_voicesS  s    	12Gx(NN7+"jj55w?ODt	9 d3ddeDkd344   	I	
 4s!   A8 A8 .A8 !B8BBc                r    \        V\        4      '       g   Q hV P                  P                  RVRV4       R# )zSwitch 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.
    
rv   LANGUAGEN)r{   r+   r   r   )r   r   r      &&&r   set_languageZSSIPClient.set_languagem  s/     (C((((

uj(Cr   c                f    V P                   P                  RR4      w  rpV'       d
   V^ ,          # R# )zGet the current language.r   r   Nr   r:   rm   r   get_languageZSSIPClient.get_languagex  s+    **11%D47Nr   c                B    V P                   P                  RVRV4       R# )zSwitch to a particular output module.

Arguments:
  name -- module (string) as returned by 'list_output_modules()'.
  scope -- see the documentation of this class.

rv   OUTPUT_MODULENr   )r   rN   r   r   r   set_output_moduleZSSIPClient.set_output_module  s     	

uotDr   c                r   )zGet the current output module.r   r   Nr   r:   rm   r   get_output_moduleZSSIPClient.get_output_module  s+    **11%I47Nr   c                    \        V\        4      '       d   RTu;8:  d   ^d8:  g   Q V4       h Q V4       hV P                  P                  RVRV4       R# )aT  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.
  
rv   PITCHNr{   rd   r   r   r   r   r   r   r   	set_pitchZSSIPClient.set_pitch  sN     %%%$%*>3*>EE>*>EE>

ugu=r   c                r   )zGet the current pitch.r   r   Nr   r:   rm   r   	get_pitchZSSIPClient.get_pitch  s+    **11%A47Nr   c                r   )al  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.
  
rv   ZPITCH_RANGENr   r   r   r   r   set_pitch_rangeZSSIPClient.set_pitch_range  sN     %%%$%*>3*>EE>*>EE>

umUCr   c                    \        V\        4      '       d   RTu;8:  d	   ^d8:  g   Q h Q hV P                  P                  RVRV4       R# )am  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.
    
rv   RATENr   r   r   r   r   set_rateZSSIPClient.set_rate  sD     %%%$%*>3*>>>*>>>

ufe<r   c                r   )z$Get the current speech rate (speed).r   r   Nr   r:   rm   r   get_rateZSSIPClient.get_rate  s+    **11%@47Nr   c                r   )a?  Set 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.
    
rv   VOLUMENr   r   r   r   r   
set_volumeZSSIPClient.set_volume  sD     %%%$%*>3*>>>*>>>

uh>r   c                r   )zGet the speech volume.r   r   Nr   r:   rm   r   
get_volumeZSSIPClient.get_volume  s+    **11%B47Nr   c                s    V\         P                  \         P                  \         P                  \         P                  39   g   Q V4       hV P
                  P                  RVRV4       R# )zSet the punctuation pronunciation level.

Arguments:
  value -- one of the 'PunctuationMode' constants.
  scope -- see the documentation of this class.
    
rv   PUNCTUATIONN)r   rz   r   r   r   r   r   r   r   r   set_punctuationZSSIPClient.set_punctuation  sa     ,,o.B.B(--/C/CE E 	LFK	L E

umUCr   c                r   )z(Get the punctuation pronunciation level.r   r   Nr   r:   rm   r   get_punctuationZSSIPClient.get_punctuation  s+    **11%G47Nr   c                s    VR9   g   Q hVR8X  d!   V P                   P                  RVRR4       R# V P                   P                  RVRR4       R# )zToggle 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.
    
Trv   ZSPELLINGr   r   N)TFr   r   r   r   set_spellingZSSIPClient.set_spelling  sI     %%%D=JJ##E5*dCJJ##E5*eDr   c                sT    VR9   g   Q hV P                   P                  RVRV4       R# )an  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.
    
rv   ZCAP_LET_RECOGNN)r   ZspellZiconr   r   r   r   set_cap_let_recognZSSIPClient.set_cap_let_recogn  s,     1111

u.>Fr   c                s    \        V\        4      '       d   VP                  4       R9   g   Q hV P                  P	                  RVRV4       R# )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.
    
rv   Z
VOICE_TYPEN)Zmale1Zmale2Zmale3Zfemale1Zfemale2Zfemale3Z
child_maleZchild_female)r{   r+   Zlowerr   r   r   r   r   	set_voiceZSSIPClient.set_voice  sH     %%%{{} !1 1	1 1 	

ulEBr   c                r   )zSet voice by its real name.

Arguments:
  value -- voice name as returned by 'list_synthesis_voices()'
  scope -- see the documentation of this class.
    
rv   ZSYNTHESIS_VOICENr   r   r   r   set_synthesis_voiceZSSIPClient.set_synthesis_voice   s     	

u.?Gr   c                r   )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.
    
rv   ZPAUSE_CONTEXTNr   r   r   r   set_pause_contextZSSIPClient.set_pause_context*  s/     %%%%%

uouEr   c                s    \        V\        4      '       g   Q hVR8X  d   RpMRpV P                  P                  R\        P
                  RV4       R# )a  Switch 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.

TZONZOFFrv   ZDEBUGN)r{   Zboolr   r   rx   rz   )r   Zvalr   r   r   	set_debugZSSIPClient.set_debug6  sD    $ #t$$$$$;HH

uyy'8Dr   c                s    \        V\        4      '       g   Q hV P                  P                  R\        P
                  RV4       R# )zSet debug destination.

Arguments:
  path -- path (string) to the directory where debugging
          files will be created
  scope -- see the documentation of this class.

rv   ZDEBUG_DESTINATIONN)r{   r+   r   r   rx   rz   )r   r   r'   r   set_debug_destinationZ SSIPClient.set_debug_destinationQ  s4     $$$$$

uyy2EtLr   c                >    V P                   P                  RR4       R# )zMBegin an SSIP block.

See SSIP documentation for more details about blocks.

BLOCKr   Nr   r"   r#   r   block_beginZSSIPClient.block_begin^  s     	

1r   c                r   )zMClose an SSIP block.

See SSIP documentation for more details about blocks.

r   r   Nr   r"   r#   r   	block_endZSSIPClient.block_endf  s     	

/r   c                sf    \        V R4      '       d   V P                  P                  4        V =R# R# )z*Close the connection to Speech Dispatcher.r   N)Zhasattrr   r^   r"   r#   r   r^   ZSSIPClient.closen  s)    4!!JJ
 "r   )r   r   r   )ZdefaultZunknownNNNNNNr/   )5r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rx   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r^   r   r0   r@   rA   r   r   r     s    * L.L5:7M;^$P 6*2X
IJ"%ND
,
: !:: 1  /  ** 0 !:: 1
54 ,1:: 	D -2JJ E &+ZZ > ,1:: D %*JJ = ',jj ? ,1:: 
D ).

 E  /4jj G &+ZZ C& 05zz H .3ZZ 
FE6M20 r   r   c                   s   a a ] tR tRt oRtR	V 3R llt]P                  3R lt]P                  3V 3R llt
]P                  3V 3R llt]P                  3V 3R lltRtVtV ;t# )
Clientiu  a  A 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                s^   < T;'       g    T;'       g    R p\         \        V `
  ! V3/ VB  R# )ZpythonN)r   r   r   )r   rN   Zclientr   r   r    r   r   ZClient.__init__~  s,    ))v))fd$T4V4r   c                sJ    V P                  V4       V P                  V4       R # r   )r   r   )r   rr   r   r   r   sayZ
Client.say  s    (#

4r   c                P   < V P                  V4       \        \        V `  V4       R # r   )r   r   r   r   )r   r   r   r      &&&r   r   ZClient.char  s     (#fd &r   c                r   r   )r   r   r   r   )r   r   r   r   r   r   r   Z
Client.key  s     (#fd$r   c                r   r   )r   r   r   r   )r   r   r   r   r   r   r   ZClient.sound_icon  s     (#fd&z2r   r   r/   )r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r0   r1   r2   r4   r   r   r   u  sN     5 "*!1!1  #+-- ' !) % /7mm 3 3r   r   c                   s    ] tR tRtRtRtR# )Speakeri  a  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.

r   Nr   r   r   r   r   r     s    r   r   c                   r   )ConnectionMethodi  zConstants describing the possible methods of connection to server.

Retained for backwards compatibility but DEPRECATED. See CommunicationMethod.rH   rI   r   NrJ   r   r   r   r   r     s    U  K;K9r   r   )r
   rO   r   r   ZtimeZtempfilerV   Zdummy_threadingZ r    Zobjectr   r6   r   r   r5   rB   rE   rF   rG   rM   r   rx   r   r   r   r   r   r   r   r   r   r   <module>r      s    . - -( )6 ).F	 F,Y ,\	  ( % 1 1:& :l"v l"\!v !B
LF 
Lv f &;v ;S
 S
l3Z 3<j ,:v :U$('s   C* *C2