o
    CZŽhx  ã                   @   s0   d dl mZ ddlZdd„ ZG dd„ deƒZdS )é   )ÚVoiceé    Nc                 C   s   t | ƒS )z¯
    Builds a new instance of a driver and returns it for use by the driver
    proxy.

    @param proxy: Proxy creating the driver
    @type proxy: L{driver.DriverProxy}
    )ÚDummyDriver)Úproxy© r   úD/var/www/auris/lib/python3.10/site-packages/pyttsx3/drivers/dummy.pyÚbuildDriver   s   r   c                   @   sX   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )r   a¢  
    Dummy speech engine implementation. Documents the interface, notifications,
    properties, and sequencing responsibilities of a driver implementation.

    @ivar _proxy: Driver proxy that manages this instance
    @type _proxy: L{driver.DriverProxy}
    @ivar _config: Dummy configuration
    @type _config: dict
    @ivar _looping: True when in the dummy event loop, False when not
    @ivar _looping: bool
    c                 C   s^   || _ d| _tddddgddƒtdd	ddgd
dƒtddddgddƒg}dd|d |dœ| _dS )z„
        Constructs the driver.

        @param proxy: Proxy creating the driver
        @type proxy: L{driver.DriverProxy}
        Fzdummy.voice1zJohn Doezen-USzen-GBZmaleÚadultzdummy.voice2zJane DoeZfemalezdummy.voice3z	Jimmy Doeé
   éÈ   g      ð?r   )ÚrateÚvolumeÚvoiceÚvoicesN)Ú_proxyÚ_loopingr   Ú_config)Úselfr   r   r   r   r   Ú__init__   s   ýüzDummyDriver.__init__c                 C   ó   dS )z¶
        Optional method that will be called when the driver proxy is being
        destroyed. Can cleanup any resources to make sure the engine terminates
        properly.
        Nr   ©r   r   r   r   Údestroy2   s   zDummyDriver.destroyc                 C   s<   d}d| _ | j r|r| j d¡ d}t d¡ | j sdS dS )zê
        Starts a blocking run loop in which driver callbacks are properly
        invoked.

        @precondition: There was no previous successful call to L{startLoop}
            without an intervening call to L{stopLoop}.
        TFg      à?N)r   r   ÚsetBusyÚtimeÚsleep)r   Úfirstr   r   r   Ú	startLoop:   s   
üzDummyDriver.startLoopc                 C   s
   d| _ dS )z´
        Stops a previously started run loop.

        @precondition: A previous call to L{startLoop} suceeded and there was
            no intervening call to L{endLoop}.
        FN)r   r   r   r   r   ÚendLoopJ   s   
zDummyDriver.endLoopc                 c   s    | j  d¡ dV  dS )z<
        Iterates from within an external run loop.
        FN)r   r   r   r   r   r   ÚiterateS   s   €
zDummyDriver.iteratec              	   C   sŒ   | j  d¡ | j  d¡ d}| d¡D ]"}| j jd|t|ƒd z| d|d ¡d }W q ty5   Y qw | j jddd	 | j  d
¡ dS )a=  
        Speaks the given text. Generates the following notifications during
        output:

        started-utterance: When speech output has started
        started-word: When a word is about to be spoken. Includes the character
            "location" of the start of the word in the original utterance text
            and the "length" of the word in characters.
        finished-utterance: When speech output has finished. Includes a flag
            indicating if the entire utterance was "completed" or not.

        The proxy automatically adds any "name" associated with the utterance
        to the notifications on behalf of the driver.

        When starting to output an utterance, the driver must inform its proxy
        that it is busy by invoking L{driver.DriverProxy.setBusy} with a flag
        of True. When the utterance completes or is interrupted, the driver
        inform the proxy that it is no longer busy by invoking
        L{driver.DriverProxy.setBusy} with a flag of False.

        @param text: Unicode text to speak
        @type text: unicode
        Tzstarted-utterancer   ú zstarted-word)ÚlocationÚlengthé   zfinished-utterance)Ú	completedFN)r   r   ÚnotifyÚsplitÚlenÚindexÚ	Exception)r   ÚtextÚiÚwordr   r   r   ÚsayZ   s   ÿzDummyDriver.sayc                 C   r   )zù
        Stops any current output. If an utterance was being spoken, the driver
        is still responsible for sending the closing finished-utterance
        notification documented above and resetting the busy state of the
        proxy.
        Nr   r   r   r   r   Ústop~   s   zDummyDriver.stopc                 C   s(   z| j | W S  ty   td| ƒ‚w )aÞ  
        Gets a property value of the speech engine. The suppoted properties
        and their values are:

        voices: List of L{voice.Voice} objects supported by the driver
        voice: String ID of the current voice
        rate: Integer speech rate in words per minute
        volume: Floating point volume of speech in the range [0.0, 1.0]

        @param name: Property name
        @type name: str
        @raise KeyError: When the property name is unknown
        úunknown property %s)r   ÚKeyError)r   Únamer   r   r   ÚgetProperty‡   s
   ÿzDummyDriver.getPropertyc                    sj   |dkrt ‡ fdd„| jd ƒ}|d | jd< d	S |dkr$ˆ | jd< d	S |dkr/ˆ | jd< d	S td| ƒ‚)
aã  
        Sets one of the supported property values of the speech engine listed
        above. If a value is invalid, attempts to clip it / coerce so it is
        valid before giving up and firing an exception.

        @param name: Property name
        @type name: str
        @param value: Property value
        @type value: object
        @raise KeyError: When the property name is unknown
        @raise ValueError: When the value cannot be coerced to fit the property
        r   c                    s
   | j ˆ kS )N)Úid)Úv©Úvaluer   r   Ú<lambda>¨   s   
 z)DummyDriver.setProperty.<locals>.<lambda>r   r   r   r   r.   N)Úfilterr   r/   )r   r0   r5   r3   r   r4   r   ÚsetPropertyš   s   zDummyDriver.setPropertyN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r,   r-   r1   r8   r   r   r   r   r      s    	$	r   )r   r   r   r   Úobjectr   r   r   r   r   Ú<module>   s   
