o
    CZhbH                     @   s  d dl mZ d dlZd dlmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZ dd Zdadd Zz	e s<edW n eyJ Z z dZ[ww d Zd	Zd
ZdZdZdZdZG dd deZG dd deZ d Z!d	Z"d
Z#dZ$d Z%dZ&d	Z'd
Z(edte	de	d	e!fde	d	dfded	dfde	d	d fZ)de)_*ee	eee	ee Z+edtdde+d	fZ,da-dd Z.de._*ee	e	eeZ/ed tdd!e/d	fZ0da1d"d# Z2d$e2_*d Z3d	Z4d
Z5dZ6d%Z7d&Z8d'Z9d(Z:d	Z;d
Z<dZ=d e;d d dfd)d*Z>ed+te	d,ed	fd-e
d	fd.ed	d fd/e	d	e;fd0ed	d fd1ed	e3fd2eed	dfd3ed	dfZ?d4e>_*d e3fd5d6Z@ed7te	d,ed	fd-ed	fd8ed	fd0ed	d fd1ed	e3fd2eed	dfd3ed	df
ZAd9e@_*ed:te	d;ed	fZBd<eB_*ed=te	d>ed	fZCd?eC_*d ZDd	ZEd
ZFdZGdZHdZIdZJd@ZKdAZLd ZMd	ZNd
ZOedBte	dCe	d	fdDe	d	fdEe	d	d fZPdFeP_*edGte	dCe	d	fZQdHeQ_*edIte	dJed	fZRdKeR_*edLtddDe	d	fdMed	fZSdNeS_*edOtdded	fdPed	fZTdQeT_*G dRdS dSeZUedTteeeUdUeeUd	fZVdVeV_*dqdWdXZWedYte	dZed	fZXd[eX_*ed\te	dUeeUd	fZYd]eY_*ed^teeUZZd_eZ_*ed`te	Z[dae[_*edbte	Z\dce\_*eddte	Z]dee]_*edfte	Z^dge^_*edhtedied	d fZ_dje__*e`dkkr{dldm Zae)e!dnZbe.ea doZced Zdeee>ec e\ r}efdp e\ spdS dS dS )r    )print_functionN)	CFUNCTYPEPOINTER	StructureUnionc_char_pc_intc_longc_shortc_ubytec_uintc_ulongc_void_pc_wcharcdllc                 G   s`   g }g }|D ]}| |d  | |d |d f|dd   qt|g|R  | |ft|S )z@build and apply a ctypes prototype complete with parameter flags      r      N)appendr   tuple)namedllresultargsZatypesZaflagsarg r   F/var/www/auris/lib/python3.10/site-packages/pyttsx3/drivers/_espeak.pycfunc	   s   $r   c               	   C   s:   g d} | D ]}z	t |aW  dS  ty   Y qw dS )N)z#/usr/local/lib/libespeak-ng.1.dylibz/usr/local/lib/libespeak.dylibzlibespeak-ng.so.1z /usr/local/lib/libespeak-ng.so.1zlibespeak.so.1z+C:\Program Files\eSpeak NG\libespeak-ng.dllz1C:\Program Files (x86)\eSpeak NG\libespeak-ng.dllTF)r   ZLoadLibraryr   	Exception)pathspathr   r   r   load_library   s   
r!   zBThis means you probably do not have eSpeak or eSpeak-ng installed!r   r   r            c                   @   s   e Zd ZdefdefgZdS )numberORnamenumberr   N)__name__
__module____qualname__r   r   _fields_r   r   r   r   r%   ?   s    r%   c                	   @   s@   e Zd ZdefdefdefdefdefdefdefdefgZd	S )
EVENTtypeunique_identifierZtext_positionlengthZaudio_positionsample	user_dataidN)r'   r(   r)   r   r   r   r%   r*   r   r   r   r   r+   F   s    r+   Zespeak_InitializeoutputZ
bufflengthd   r    optiona  Must be called before any synthesis functions are called.
  output: the audio data can either be played by eSpeak or passed back by the SynthCallback function. 
  buflength:  The length in mS of sound buffers passed to the SynthCallback function.
  path: The directory which contains the espeak-data directory, or NULL for the default location.
  options: bit 0: 1=allow espeakEVENT_PHONEME events.

  Returns: sample rate in Hz, or -1 (EE_INTERNAL_ERROR).Zespeak_SetSynthCallbackSynthCallbackc                 C   s   t | att d S N)t_espeak_callbackr6   cSetSynthCallbackcbr   r   r   SetSynthCallbackq      r<   av  Must be called before any synthesis functions are called.
   This specifies a function in the calling program which is called when a buffer of
   speech sound data has been produced. 


   The callback function is of the form:

int SynthCallback(short *wav, int numsamples, espeak_EVENT *events);

   wav:  is the speech sound data which has been produced.
      NULL indicates that the synthesis has been completed.

   numsamples: is the number of entries in wav.  This number may vary, may be less than
      the value implied by the buflength parameter given in espeak_Initialize, and may
      sometimes be zero (which does NOT indicate end of synthesis).

   events: an array of espeak_EVENT items which indicate word and sentence events, and
      also the occurance if <mark> and <audio> elements within the text.


   Callback returns: 0=continue synthesis,  1=abort synthesis.Zespeak_SetUriCallbackUriCallbackc                 C   s   t tatt d S r7   )t_UriCallbackr>   cSetUriCallbackr:   r   r   r   SetUriCallback   r=   rA   ap  This function must be called before synthesis functions are used, in order to deal with
   <audio> tags.  It specifies a callback function which is called when an <audio> element is
   encountered and allows the calling program to indicate whether the sound file which
   is specified in the <audio> element is available and is to be played.

   The callback function is of the form:

int UriCallback(int type, const char *uri, const char *base);

   type:  type of callback event.  Currently only 1= <audio> element

   uri:   the "src" attribute from the <audio> element

   base:  the "xml:base" attribute (if any) from the <speak> element

   Return: 1=don't play the sound, but speak the text alternative.
           0=place a PLAY event in the event list at the point where the <audio> element
             occurs.  The calling program can then play the sound at that point.      i   i    c              	   C   s   t | t| d ||||d |S )N
   )cSynthlen)textpositionposition_typeend_positionflagsr0   r   r   r   Synth   s   rL   Zespeak_SynthrG   sizerH   rI   rJ   rK   r-   r0   a  Synthesize speech for the specified text.  The speech sound data is passed to the calling
   program in buffers by means of the callback function specified by espeak_SetSynthCallback(). The command is asynchronous: it is internally buffered and returns as soon as possible. If espeak_Initialize was previously called with AUDIO_OUTPUT_PLAYBACK as argument, the sound data are played by eSpeak.

   text: The text to be spoken, terminated by a zero character. It may be either 8-bit characters,
      wide characters (wchar_t), or UTF8 encoding.  Which of these is determined by the "flags"
      parameter.

   size: Equal to (or greater than) the size of the text data, in bytes.  This is used in order
      to allocate internal storage space for the text.  This value is not used for
      AUDIO_OUTPUT_SYNCHRONOUS mode.

   position:  The position in the text where speaking starts. Zero indicates speak from the
      start of the text.

   position_type:  Determines whether "position" is a number of characters, words, or sentences.
      Values: 

   end_position:  If set, this gives a character position at which speaking will stop.  A value
      of zero indicates no end position.

   flags:  These may be OR'd together:
      Type of character codes, one of:
         espeak.CHARS_UTF8     UTF8 encoding
         espeak.CHARS_8BIT     The 8 bit ISO-8859 character set for the particular language.
         espeak.CHARS_AUTO     8 bit or UTF8  (this is the default)
         espeak.CHARS_WCHAR    Wide characters (wchar_t)

      espeak.SSML   Elements within < > are treated as SSML elements, or if not recognised are ignored.

      espeak.PHONEMES  Text within [[ ]] is treated as phonemes codes (in espeak's Hirschenbaum encoding).

      espeak.ENDPAUSE  If set then a sentence pause is added at the end of the text.  If not set then
         this pause is suppressed.

   unique_identifier: message identifier; helpful for identifying later 
     data supplied to the callback.

   user_data: pointer which will be passed to the callback function.

   Return: EE_OK: operation achieved 
           EE_BUFFER_FULL: the command can not be buffered; 
             you may try after a while to call the function again.
	   EE_INTERNAL_ERROR.c                 C   s   t | t| d ||| d S )Nr   )cSynth_MarkrF   )rG   
index_markrJ   rK   r   r   r   
Synth_Mark   s   rP   Zespeak_Synth_MarkrO   a!  Synthesize speech for the specified text.  Similar to espeak_Synth() but the start position is
   specified by the name of a <mark> element in the text.

   index_mark:  The "name" attribute of a <mark> element within the text which specified the
      point at which synthesis starts.  UTF8 string.

   For the other parameters, see espeak_Synth()

   Return:  EE_OK: operation achieved 
            EE_BUFFER_FULL: the command can not be buffered; 
             you may try after a while to call the function again.
	        EE_INTERNAL_ERROR.Z
espeak_KeyZkey_namea  Speak the name of a keyboard key.
   Currently this just speaks the "key_name" as given 

   Return: EE_OK: operation achieved 
           EE_BUFFER_FULL: the command can not be buffered; 
             you may try after a while to call the function again.
	   EE_INTERNAL_ERROR.Zespeak_Char	characterzSpeak the name of the given character 

   Return: EE_OK: operation achieved 
           EE_BUFFER_FULL: the command can not be buffered; 
             you may try after a while to call the function again.
	   EE_INTERNAL_ERROR.      Zespeak_SetParameterZ	parametervalueZrelativeaD  Sets the value of the specified parameter.
   relative=0   Sets the absolute value of the parameter.
   relative=1   Sets a relative value of the parameter.

   parameter:
      espeak.RATE:    speaking speed in word per minute.

      espeak.VOLUME:  volume in range 0-100    0=silence

      espeak.PITCH:   base pitch, range 0-100.  50=normal

      espeak.RANGE:   pitch range, range 0-100. 0-monotone, 50=normal

      espeak.PUNCTUATION:  which punctuation characters to announce:
         value in espeak_PUNCT_TYPE (none, all, some), 
         see espeak_GetParameter() to specify which characters are announced.

      espeak.CAPITALS: announce capital letters by:
         0=none,
         1=sound icon,
         2=spelling,
         3 or higher, by raising pitch.  This values gives the amount in Hz by which the pitch
            of a word raised to indicate it has a capital letter.

   Return: EE_OK: operation achieved 
           EE_BUFFER_FULL: the command can not be buffered; 
             you may try after a while to call the function again.
           EE_INTERNAL_ERROR.Zespeak_GetParameterzcurrent=0  Returns the default value of the specified parameter.
   current=1  Returns the current value of the specified parameter, as set by SetParameter()Zespeak_SetPunctuationListZ	punctlista  Specified a list of punctuation characters whose names are 
to be spoken when the value of the Punctuation parameter is set to "some".

   punctlist:  A list of character codes, terminated by a zero character.

   Return:  EE_OK: operation achieved 
            EE_BUFFER_FULL: the command can not be buffered; 
             you may try after a while to call the function again.
            EE_INTERNAL_ERROR.Zespeak_SetPhonemeTracestreamam  Controls the output of phoneme symbols for the text
   value=0  No phoneme output (default)
   value=1  Output the translated phoneme symbols for the text
   value=2  as (1), but also output a trace of how the translation was done (matching rules and list entries)

   stream   output stream for the phoneme symbols (and trace).  If stream=NULL then it uses stdout.Zespeak_CompileDictionaryloga  Compile pronunciation dictionary for a language which corresponds to the currently
   selected voice.  The required voice should be selected before calling this function.

   path:  The directory which contains the language's '_rules' and '_list' files.
          'path' should end with a path separator character ('/').
   log:   Stream for error reports and statistics information. If log=NULL then stderr will be used.c                
   @   sN   e Zd Zdefdefdefdefdefdefdefdefd	efg	Zd
d ZdS )VOICEr   	languages
identifierZgenderZagevariantZxx1ZscoreZsparec              
   C   sN   g }| j D ]}|d|d tt| |d f  q| jjd d| d S )zPrint the fieldsz%s=%sr   (,))r*   r   reprgetattr	__class__r'   join)selfresfieldr   r   r   __repr__  s   
&zVOICE.__repr__N)	r'   r(   r)   r   r   r   r   r*   re   r   r   r   r   rW   y  s    rW   Zespeak_ListVoices
voice_specaO  Reads the voice files from espeak-data/voices and creates an array of espeak_VOICE pointers.
   The list is terminated by a NULL pointer

   If voice_spec is NULL then all voices are listed.
   If voice spec is given, then only the voices which are compatible with the voice_spec
   are listed, and they are listed in preference order.c                 C   s>   t | }g }d}|| r||| d  |d7 }|| s|S )a  Reads the voice files from espeak-data/voices and returns a list of VOICE objects.

   If voice_spec is None then all voices are listed.
   If voice spec is given, then only the voices which are compatible with the voice_spec
   are listed, and they are listed in preference order.r   r   )cListVoicesr   )rf   Zppvrc   ir   r   r   
ListVoices  s   ri   Zespeak_SetVoiceByNamer   a6  Searches for a voice with a matching "name" field.  Language is not considered.
   "name" is a UTF8 string.

   Return:   EE_OK: operation achieved 
             EE_BUFFER_FULL: the command can not be buffered; 
             you may try after a while to call the function again.
             EE_INTERNAL_ERROR.Zespeak_SetVoiceByPropertiesaA  An espeak_VOICE structure is used to pass criteria to select a voice.  Any of the following
   fields may be set:

   name     NULL, or a voice name

   languages  NULL, or a single language string (with optional dialect), eg. "en-uk", or "en"

   gender   0=not specified, 1=male, 2=female

   age      0=not specified, or an age in years

   variant  After a list of candidates is produced, scored and sorted, "variant" is used to index
            that list and choose a voice.
            variant=0 takes the top voice (i.e. best match). variant=1 takes the next voice, etcZespeak_GetCurrentVoicezReturns the espeak_VOICE data for the currently selected voice.
   This is not affected by temporary voice changes caused by SSML elements such as <voice> and <s>Zespeak_Cancela  Stop immediately synthesis and audio output of the current text. When this
   function returns, the audio output is fully stopped and the synthesizer is ready to
   synthesize a new message.

   Return:  EE_OK: operation achieved 
            EE_INTERNAL_ERROR.Zespeak_IsPlayingz*Returns 1 if audio is played, 0 otherwise.Zespeak_SynchronizezxThis function returns when all data have been spoken.
   Return:  EE_OK: operation achieved 
	        EE_INTERNAL_ERROR.Zespeak_Terminatez^last function to be called.
   Return:  EE_OK: operation achieved 
	        EE_INTERNAL_ERROR.Zespeak_InfoZptrz]Returns the version number string.
The parameter is for future use, and should be set to NULL__main__c                 C   sB   t |dd d}	 || jtkr	 dS t || jdd |d7 }q	)N )endr   Tr   )printr,   EVENT_LIST_TERMINATED)ZwavZ	numsampleeventsrh   r   r   r   synth_cb  s   rp   )r3   zThis is a test, only a test. g?r7   )g
__future__r   timectypesr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r!   RuntimeErrorr   exprn   Z
EVENT_WORDZEVENT_SENTENCEZ
EVENT_MARKZ
EVENT_PLAYZ	EVENT_ENDZEVENT_MSG_TERMINATEDr%   r+   ZAUDIO_OUTPUT_PLAYBACKZAUDIO_OUTPUT_RETRIEVALZAUDIO_OUTPUT_SYNCHRONOUSZAUDIO_OUTPUT_SYNCH_PLAYBACKZEE_OKZEE_INTERNAL_ERRORZEE_BUFFER_FULLZEE_NOT_FOUNDZ
Initialize__doc__r8   r9   r6   r<   r?   r@   r>   rA   Z
CHARS_AUTOZ
CHARS_UTF8Z
CHARS_8BITZCHARS_WCHARZSSMLZPHONEMESZENDPAUSEZKEEP_NAMEDATAZPOS_CHARACTERZPOS_WORDZPOS_SENTENCErL   rE   rP   rN   KeyCharZSILENCEZRATEZVOLUMEZPITCHRANGEPUNCTUATIONZCAPITALSZEMPHASISZ
LINELENGTHZ
PUNCT_NONEZ	PUNCT_ALLZ
PUNCT_SOMEZSetParameterZGetParameterZSetPunctuationListZSetPhonemeTraceZCompileDictionaryrW   rg   ri   ZSetVoiceByNameZSetVoiceByPropertiesZGetCurrentVoiceZCancelZ	IsPlayingZSynchronizeZ	TerminateZInfor'   rp   Z
sampleratesuidrm   sleepr   r   r   r   <module>   sP   @









	-








