
    g
f                     t    d Z dZdZdZdZdZdZddlmZm	Z	 d	d
l
mZ d	dl
mZ  G d de      Z G d de      Zy)zSSML --- XML-based markup language for speech synthesis.

Class SSML defines a simple wrapper for holding and converting
text to SSML, suitable to be sent to a speech server. Services
can pass flags to control the elements and attributes used.
z$Id$z
$Revision$z$Date$z<andyholmes@gnome.org>u(   Copyright © 2024 GNOME Foundation Inc. LGPL    )Enumauto   )debug)script_managerc                       e Zd ZdZ e       Z e       Z e       Z e       Z e       Z	 e       Z
 e       Z e       Z e       Z e       Z e       Z e       Z e       Z e       Z e       Z e       Z e       Zy)SSMLCapabilitiesz!Enumeration of SSML capabilities.N)__name__
__module____qualname____doc__r   SAY_AS_DATESAY_AS_TIMESAY_AS_TELEPHONESAY_AS_CHARACTERSSAY_AS_CHARACTERS_GLYPHSSAY_AS_CARDINALSAY_AS_ORDINALSAY_AS_CURRENCYBREAKSUBPHONEMEEMPHASISPROSODYMARKSENTENCE_PARAGRAPHTOKENALL     +/usr/lib/python3/dist-packages/orca/ssml.pyr
   r
   )   s    +&K&Kv#vfOVNfOFE
&CfGvHfG6DFE
&Cr!   r
   c                   z    e Zd ZdZdej
                  fdZd Zed        Z	eej
                  fd       Z
d Zd Zy	)
SSMLz*Holds SSML representation of an utterance. c                 \    t         j                  |        |xs d| d<   t        |      | d<   y)z%Create and initialize ACSS structure.r%   textfeaturesN)dict__init__r
   )selfr'   r(   s      r"   r*   zSSML.__init__@   s*    dzrV+H5Zr!   c                     t        |t              sy| j                  d      |j                  d      k7  ry| j                  d      |j                  d      k7  ryy)NFr'   r(   T)
isinstancer$   get)r+   others     r"   __eq__zSSML.__eq__F   sL    %&88Fuyy0088J599Z#88r!   c                    d}g }d}d}t        t        |             D ]  }| |   }|dk(  r|j                         s||dz  }|}|j                         }n|j                         r||rt        |dz   t        |             D ]  }| |   j                         r n d}|r_t        |       k  rQ| |   j                         s>| |   j                         sd}|dz  }|r"|t        |       k  r| |   j                         s>|s,|j	                  ||f       d}d}n|r|j                         sd}||z  } ||j	                  |dz   f       ||fS )z3Mark the word offsets of text for later formatting.r%   N   r   F)rangelenisspace	isnumericappend)r'   markedoffsets
last_begin
is_numericicjs           r"   _mark_wordszSSML._mark_wordsO   sl    

s4y! &	AQAH} 99;:#5("
[[]
!7 #1Q3D	2 +#Aw0!+ &+
$SYtAw?P#Aw002).JQ %SYtAw?P
 "NNJ?3!%J!%JAKKM"
aKFM&	P !NNJA./  r!   c                    | xs d} |dk(  r| S t         j                  |       \  } }t        j                         j	                         }||j
                  j                  |       } d}d}| D ]w  }|dk(  rJ|t        |      k\  r+| d}t        j                  t        j                  |d       n|d||   z  z  }|dz  }R|d	k(  r|d
z  }]|dk(  r|dz  }h|dk(  r|dz  }s||z  }y |dz  }|S )a  Converts plain text to SSML markup.  If features is 0, the text
        will be returned unmodified.

        Arguments:
        - text:      optional text to add to the queue before speaking
        - features:  ssml.SSMLCapabilities flags. Currently, the only
                     supported element is SSMLCapabilities.MARK.

        Returns:
        - The SSML markup of the text, per the supported features.
        r%   r   z<speak>r2   z+th U+E000 does not have corresponding indexTz<mark name="%u:%u"/>r   <z&lt;>z&gt;&z&amp;z</speak>)r$   r?   r   
getManagergetActiveScript	utilitiesadjustForPronunciationr4   r   printMessageLEVEL_WARNING)r'   r(   r9   scriptssmlr<   r=   msgs           r"   
markupTextzSSML.markupText   s     zrq=K **40w  **,<<>##::4@D
  	AH}G$CJKC&&u':':CF2WQZ??DQ ccc	+	, 	
r!   c                 :    t         j                  | d   | d         S )z;Return the text content as SSML, per the supported featuresr'   r(   )r$   rM   r+   s    r"   	getMarkupzSSML.getMarkup   s    tF|T*-=>>r!   c                     | d   S )Nr'   r    rO   s    r"   getTextzSSML.getText   s    F|r!   N)r   r   r   r   r
   r   r*   r0   staticmethodr?   rM   rP   rR   r    r!   r"   r$   r$   =   sX    4)9)=)= 6 8! 8!t "2"6"6 6 6p?r!   r$   N)r   __id____version____date__
__author____copyright____license__enumr   r   r%   r   r   r
   r)   r$   r    r!   r"   <module>r[      sM   , 
(
:   t (K4 Kr!   