mò
/5+Hc           @   s°   d  Z  d Z d Z d Z d Z d Z d Z d g Z d k Z d k	 Z	 d f  d	 „  ƒ  YZ
 d
 „  Z h  d d <d d <d d <d d <Z d „  Z e d j o e ƒ  n d S(   su  Python wrapper for Emacspeak speech servers.

The emacspeak TTS server provides a simple but powerful and
well-tested speech-server abstraction. That server is implemented
as an external program (typically in TCL).  This wrapper class
provides Python access to available Emacspeak speech servers.

Initially, this class will provide Python access to the TTS
server commands.  Over time, this module may also implement
functionality present in Emacspeak's Lisp layer ---specifically,
higher level TTS functionality provided by the following
emacspeak modules:

0)  dtk-speak.el

1)  emacspeak-pronounce.el

2)  accs-structure.el

s7   $Id: speaker.py 5568 2008-05-09 14:14:23Z tv.raman.tv $s   $Author: tv.raman.tv $s   $Revision: 5568 $s5   $Date: 2008-05-09 07:14:23 -0700 (Fri, 09 May 2008) $s   Copyright (c) 2005 T. V. Ramant   LGPLt   SpeakerNc           B   sL  t  Z d  Z d Z h  d d <d d <d d <d d <d	 d
 <Z d „  Z e e ƒ Z d d e d „ Z d „  Z d „  Z	 d e
 d „ Z e
 d „ Z e
 d „ Z d „  Z d d d „ Z d d „ Z d e
 d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d  „  Z d! d" „ Z d! d# „ Z d$ „  Z d% „  Z d& „  Z d' „  Z RS((   sÌ  Provides speech servre abstraction.

    Class Variables:

        location -- specifies directory where Emacspeak
        speech servers are installed.

        config --  dictionary of default settings.
    
    Speaker objects can be initialized with the following parameters:

        engine -- TTS server to instantiate. Default: outloud
        host -- Host that runs   server. Default: localhost
        settings -- Dictionary of default settings.

    s,   /usr/share/emacs/site-lisp/emacspeak/serverst	   splitcapsi   t   rateiF   t
   capitalizei    t   allcapst   punctuationst   allc          C   s   t  t i i t i d ƒ ƒ } g  }  xL | D]D } | d d j p | i	 ƒ  d j o q+ n |  i
 | i	 ƒ  ƒ q+ W| i ƒ  |  S(   s   Enumerate available engines.s   .serversi    t   #t    N(   t   opent   ost   patht   joinR   t   locationt   ft   enginest   linet   stript   appendt   close(   R   R   R   (    (    tD   /usr/local/share/emacs/site-lisp/emacspeak/servers/python/speaker.pyt   listEngines<   s      $ 
t   outloudt	   localhostc         C   sú   | |  _ t t | ƒ ƒ } | i |  _ | i |  _ | d j o" t	 i
 i t i |  i ƒ |  _ n# t	 i
 i t i d |  i ƒ |  _ d |  i d } t	 i | d d ƒ \ |  _ |  _ |  _ h  |  _ | d j	 o$ |  i i | ƒ |  i |  i ƒ n d S(   s   Launches speech engine.R   s   ssh-%ss   { s   ; } 2>&1t   wi   N(   t   enginet   selft   _enginet
   __import__t	   _getcodest   et   getvoicet   getratet   hostR   R   R   R   R   t   _servert   cmdt   popen3t   _wt   _rt   _et	   _settingst   initialt   Nonet   updatet	   configure(   R   R   R"   R*   R$   R   (    (    R   t   __init__H   s     	"'	c         C   s\   xU | i ƒ  D]G } t |  | ƒ o1 t t |  | ƒ ƒ o t |  | ƒ | | ƒ q q Wd S(   s   Configure engine with settings.N(   t   settingst   keyst   kt   hasattrR   t   callablet   getattr(   R   R/   R1   (    (    R   R-   _   s
      &c         C   s   |  i S(   N(   R   R)   (   R   (    (    R   R/   e   s    R	   c         C   s   t  | d ƒ i d ƒ } t  | d ƒ i d ƒ } | d j	 o8 |  i | ƒ } |  i i	 d | d | | d f ƒ n |  i i	 d | ƒ d S(   s=   Speaks specified text. All queued text is spoken immediately.s   utf-8s	   iso8859-1s   q {%s %s %s}
d
i    i   s	   q {%s}
d
N(
   t   unicodet   textt   encodet   acssR+   R   R    t   codeR&   t   write(   R   R6   R8   R9   (    (    R   t   sayg   s     )c         C   s   |  i | | ƒ d  S(   N(   R   R;   R6   R8   (   R   R6   R8   (    (    R   t   speakq   s    c         C   s›   | d j	 oO |  i | ƒ } xh | D]1 } |  i i d | d t	 | ƒ | d f ƒ q# Wn, x( | D]  } |  i i d t	 | ƒ ƒ qc W|  i i d ƒ d S(   s   Speak list of utterances.s   q { %s %s %s }
i    i   s	   q { %s }
s   d
N(
   R8   R+   R   R    R9   t   listt   tR&   R:   t   str(   R   R=   R8   R9   R>   (    (    R   t   sayUtterancess   s      3 c         C   s   |  i i d | ƒ d S(   s   Speak single character.s   l {%s}
N(   R   R&   R:   t   l(   R   RA   (    (    R   t   letter~   s     i¸  i2   c         C   s   |  i i d | | f ƒ d S(   s   Queue specified tone.s	   t %s %s
 N(   R   R&   R:   t   pitcht   duration(   R   RC   RD   (    (    R   t	   queueTone‚   s     c         C   s   |  i i d | ƒ d S(   s   Queue specified silence.s   sh  %sN(   R   R&   R:   RD   (   R   RD   (    (    R   t   queueSilence†   s     c         C   s]   | d j	 o8 |  i | ƒ } |  i i d | d | | d f ƒ n |  i i d | ƒ d S(   sU   Queue text to be spoken.
        Output is produced by next call to say() or speak().s   q {%s %s %s}
i    i   s   q {%s}
N(   R8   R+   R   R    R9   R&   R:   R6   (   R   R6   R8   R9   (    (    R   t	   queueTextŠ   s
     )c         C   s   |  i i d ƒ d S(   s   Silence ongoing speech.s   s
N(   R   R&   R:   (   R   (    (    R   t   stop”   s     c         C   s;   |  i i ƒ  |  i i ƒ  |  i i ƒ  t i i d ƒ d S(   s   Shutdown speech engine.s   shut down TTS
N(   R   R&   R   R'   R(   t   syst   stderrR:   (   R   (    (    R   t   shutdown˜   s
     c         C   s   |  i i d ƒ d S(   s   Reset TTS engine.s
   tts_reset
N(   R   R&   R:   (   R   (    (    R   t   resetŸ   s     c         C   s   |  i i d ƒ d S(   s   Speak TTS version info.s   version
N(   R   R&   R:   (   R   (    (    R   t   version£   s     c         C   s?   | d d d g j o% | |  i d <|  i i d | ƒ n d S(   s   Set punctuation mode.R   t   somet   noneR   s   tts_set_punctuations %s
N(   t   modeR   R)   R&   R:   (   R   RP   (    (    R   R   §   s     c         C   s.   | |  i d <|  i i d |  i | ƒ ƒ d S(   s   Set speech rate.R   s   tts_set_speech_rate %s
N(   t   rR   R)   R&   R:   R!   (   R   RQ   (    (    R   R   ­   s     i
   c         C   s;   |  i d c | 7<|  i i d |  i |  i d ƒ ƒ d S(   s   Set speech rate.R   s   tts_set_speech_rate %s
N(   R   R)   t   stepR&   R:   R!   (   R   RR   (    (    R   t   increaseRate²   s     c         C   s;   |  i d c | 8<|  i i d |  i |  i d ƒ ƒ d S(   s   Set speech rate.R   s   tts_set_speech_rate %s
N(   R   R)   RR   R&   R:   R!   (   R   RR   (    (    R   t   decreaseRate·   s     c         C   s?   t  | ƒ o d p d } | |  i d <|  i i d | ƒ d S(   s,   Set splitcaps mode. 1  turns on, 0 turns offi   i    R   s   tts_split_caps %s
N(   t   boolt   flagR   R)   R&   R:   (   R   RV   (    (    R   R   ¼   s     c         C   s?   t  | ƒ o d p d } | |  i d <|  i i d | ƒ d S(   s2   Set capitalization  mode. 1  turns on, 0 turns offi   i    R   s   tts_capitalize %s
N(   RU   RV   R   R)   R&   R:   (   R   RV   (    (    R   R   Â   s     c         C   s?   t  | ƒ o d p d } | |  i d <|  i i d | ƒ d S(   s+   Set allcaps  mode. 1  turns on, 0 turns offi   i    R   s   tts_allcaps_beep %s
N(   RU   RV   R   R)   R&   R:   (   R   RV   (    (    R   R   È   s     c         C   s   |  i i p |  i ƒ  n d S(   s   Shutdown speech engine.N(   R   R&   t   closedRK   (   R   (    (    R   t   __del__Î   s      (   t   __name__t
   __module__t   __doc__R   t   configR   t   staticmethodR.   R-   R/   R+   R;   R<   R@   RB   RE   RF   RG   RH   RK   RL   RM   R   R   RS   RT   R   R   R   RX   (    (    (    R   R       s6    3	
		
	
									c         C   s   t  |  S(   N(   t
   _codeTableR   (   R   (    (    R   R   Ò   s    s   dtk-expt   dectalks   dtk-mvs   dtk-softR   c          C   sô   d k  } d k } t ƒ  } | i ƒ  }  | i d ƒ | i d ƒ | i d ƒ xv d d d d g D]b } x> t	 d	 d
 d ƒ D]* } | |  | <| i d | | f |  ƒ qz W|  | =| i d | |  ƒ qa W| i d ƒ d GH| i d ƒ | i ƒ  d S(   s
   Self test.NR   s   This is an initial test. test.s(   Next, we'll test audio formatted output.s   average-pitchs   pitch-ranget   richnesst   stressi    i
   i   s   Set %s to %i. s	   Reset %s.R	   s/   sleeping  while waiting for speech to complete.i(   (   t   timeR8   R   t   st   ACSSt   aR   RG   t   dt   ranget   iR<   t   sleepRK   (   Re   Rf   Rh   R8   Rc   Rb   (    (    R   t   _testÛ   s(     			  
t   __main__(   R[   t   __id__t
   __author__t   __version__t   __date__t   __copyright__t   __license__t   __all__R   RI   R   R   R^   Rj   RY   (   RI   Rp   Rr   Rq   R^   Rm   Ro   R   Rl   R   Rn   R   Rj   (    (    R   t   ?   s   	²	*	 