
    PiH2                        d Z ddlZddlZddlmZ ddlmZmZmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZ ddlmZmZ ed         Zddedddd ej                    ddddd e            fde dedee         de!de!de!de!dee e	f         de!dee!e f         ded ed!e"d"efd#Z#dede!dee!e f         deded efd$Z$ded%ee ee          f         dede!d!e"de!de!fd&Z%dS )'zjProvides the phonemize function

To use it in your own code, type:

    from phonemizer import phonemize

    N)Logger)OptionalUnionListPattern)Literal)BACKENDS)BaseBackend)LanguageSwitch)WordMismatch)
get_logger)Punctuation)default_separator	Separator)list2strstr2listespeakespeak-mbrolafestivalsegmentszen-usr   F
keep-flagsignore   languagebackend	separatorstripprepend_textpreserve_empty_linespreserve_punctuationpunctuation_markswith_stresstielanguage_switchwords_mismatchnjobsloggerc           
         t           j        dk     r3|                    dd                    t           j                             t	          ||	|
|||           |dk    r|r|                    d           |dk    r|j        r|                    d           |dk    rt          |         ||||	|
|||          }n7|dk    rt          |         ||	          }nt          |         ||||
          }t          || |||||          S )u  Multilingual text to phonemes converter

    Return a phonemized version of an input `text`, given its `language` and a
    phonemization `backend`.

    Note
    ----

    To improve the processing speed it is better to minimize the calls to this
    function: provide the input text as a list and call phonemize() a single
    time is much more efficient than calling it on each element of the list.
    Indeed the initialization of the phonemization backend can be expensive,
    especially for espeak. In one example,

    Do this:

    >>> text = [line1, line2, ...]
    >>> phonemize(text, ...)

    Not this:

    >>> for line in text:
    >>>     phonemize(line, ...)

    Parameters
    ----------

    text: str or list of str
        The text to be phonemized. Any empty line will
        be ignored. If ``text`` is an str, it can be multiline (lines being
        separated by ``\n``). If ``text`` is a list, each element is considered as a
        separated line. Each line is considered as a text utterance.

    language: str
        The language code of the input text, must be supported by
        the backend. If ``backend`` is 'segments', the language can be a file with
        a grapheme to phoneme mapping.

    backend: str, optional
        The software backend to use for phonemization,
        must be 'festival' (US English only is supported, coded 'en-us'),
        'espeak', 'espeak-mbrola' or 'segments'.

    separator: Separator
        string separators between phonemes, syllables and
        words, default to separator.default_separator. Syllable separator is
        considered only for the festival backend. Word separator is ignored by
        the 'espeak-mbrola' backend. Initialize it as follows:
            >>> from phonemizer.separator import Separator
            >>> separator = Separator(phone='-', word=' ')

    strip: bool, optional
        If True, don't output the last word and phone
        separators of a token, default to False.

    prepend_text: bool, optional
        When True, returns a pair (input utterance,
        phonemized utterance) for each line of the input text. When False,
        returns only the phonemized utterances. Default to False

    preserve_empty_lines: bool, optional
        When True, will keep the empty lines
        in the phonemized output. Default to False and remove all empty lines.

    preserve_punctuation: bool, optional
        When True, will keep the punctuation
        in the phonemized output. Not supported by the 'espeak-mbrola' backend.
        Default to False and remove all the punctuation.

    punctuation_marks: str or re.Pattern, optional
        The punctuation marks to consider when dealing with punctuation,
        either for removal or preservation.  Can be defined as a string or regular expression.
        Default to Punctuation.default_marks().

    with_stress: bool, optional
        This option is only valid for the 'espeak'
        backend. When True the stresses on phonemes are present (stresses
        characters are ˈ'ˌ). When False stresses are removed. Default to False.

    tie: bool or char, optional
        This option is only valid for the 'espeak'
        backend with espeak>=1.49. It is incompatible with phone separator. When
        not False, use a tie character within multi-letter phoneme names. When
        True, the char 'U+361' is used (as in d͡ʒ), 'z' means ZWJ character,
        default to False.

    language_switch: str, optional
        Espeak can output some words in another
        language (typically English) when phonemizing a text. This option setups
        the policy to use when such a language switch occurs. Three values are
        available : 'keep-flags' (the default), 'remove-flags' or
        'remove-utterance'. The 'keep-flags' policy keeps the language switching
        flags, for example "(en) or (jp)", in the output. The 'remove-flags'
        policy removes them and the 'remove-utterance' policy removes the whole
        line of text including a language switch. This option is only valid for
        the 'espeak' backend.

    words_mismatch: str, optional
        Espeak can join two consecutive words or
        drop some words, yielding a word count mismatch between orthographic and
        phonemized text. This option setups the policy to use when such a words
        count mismatch occurs. Three values are available: 'ignore' (the default)
        which do nothing, 'warn' which issue a warning for each mismatched line,
        and 'remove' which remove the mismatched lines from the output.

    njobs: int
        The number of parallel jobs to launch. The input text is split
        in ``njobs`` parts, phonemized on parallel instances of the backend and the
        outputs are finally collapsed.

    logger: logging.Logger
        the logging instance where to send messages. If
        not specified, use the default system logger.

    Returns
    -------
    phonemized text: str or list of str
        The input ``text`` phonemized for the
        given ``language`` and ``backend``. The returned value has the same type of
        the input text (either a list or a string), excepted if ``prepend_input``
        is True where the output is forced as a list of pairs (input_text,
        phonemized text).

    Raises
    ------
    RuntimeError
        if the ``backend`` is not valid or is valid but not installed,
        if the ``language`` is not supported by the ``backend``, if any incompatible options are used.

    )      z]Your are using python-%s which is unsupported by the phonemizer, please update to python>=3.6.r   z1espeak-mbrola backend cannot preserve punctuationz5espeak-mbrola backend cannot preserve word separationr   )r"   r!   r#   r$   r%   r&   r(   )r(   )r"   r!   r(   )	sysversion_infoerrorjoin_check_argumentswarningwordr	   
_phonemize)textr   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   
phonemizers                   h/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/phonemizer/phonemize.py	phonemizer8   *   sd   f &  +,/HHS5E,F,F	H 	H 	H
 c9o~O O O /!!&:!JKKK/!!in!NOOO (g&/!5#+)  

 
O	#	#g&  

 g&/!5	  
 j$	5%Ocddd    c                     | dvr6t          d                    | d                    d                              |r(| dk    r"t          d                    |                     |r(| dk    r"t          d                    |                     |r|j        rt          d|j         d          |d	k    r(| dk    r"t          d
                    |                     |dk    r(| dk    r$t          d                    |                     dS dS )zAuxiliary function to phonemize()

    Ensures the parameters are compatible with each other, raises a
    RuntimeError the first encountered error.

    r   z,{} is not a supported backend, choose in {}.z, r   z[the "with_stress" option is available for espeak backend only, but you are using {} backendzSthe "tie" option is available for espeak backend only, but you are using {} backendzAthe "tie" option is incompatible with phone separator (which is "z")r   z_the "language_switch" option is available for espeak backend only, but you are using {} backendr   z^the "words_mismatch" option is available for espeak backend only, but you are using {} backendN)RuntimeErrorformatr0   phone)r   r#   r$   r   r%   r&   s         r7   r1   r1      s    III:C"E "E F FG G 	G  <w(**++16'??< < 	<
  <w(""++16'??< < 	<
  /y /.#/. . ./ / 	/
 ,&&7h+>+>117B B 	B
 !!g&9&9117B B 	B "!&9&9r9   r5   c                    t          |          }d t          |          D             }|rd t          |          D             }d |D             }|r|                     ||||          }	ng }	|r3|D ]0}
|r|                    |
d           |	                    |
d           1|rt          t          ||	                    S |t          k    rt          |	          S |	S )zAuxiliary function to phonemize()

    Does the phonemization and returns the phonemized text. Raises a
    RuntimeError on error.

    c                 L    g | ]!}|                     t          j                  "S  )r   oslinesep.0lines     r7   
<listcomp>z_phonemize.<locals>.<listcomp>+  s&    >>>tDJJrz"">>>r9   c                 @    g | ]\  }}|                                 |S r@   r   )rD   nrE   s      r7   rF   z_phonemize.<locals>.<listcomp>/  s)    LLLWQtzz||LqLLLr9   c                 :    g | ]}|                                 |S r@   rH   rC   s     r7   rF   z_phonemize.<locals>.<listcomp>2  s%    222TTZZ\\2D222r9   )r   r   r'    )	typer   	enumerater8   insertlistzipstrr   )r   r5   r   r   r'   r   r    	text_typeempty_lines
phonemizedis              r7   r4   r4     s(    T

I ?>x~~>>>D  MLL	$LLL 32T222D &&IU% ' A A

 
  % 	% 	%A #Ar"""a$$$$  +Cj))***C
###r9   )&__doc__rA   r-   loggingr   typingr   r   r   r   typing_extensionsr   phonemizer.backendr	   phonemizer.backend.baser
   )phonemizer.backend.espeak.language_switchr   (phonemizer.backend.espeak.words_mismatchr   phonemizer.loggerr   phonemizer.punctuationr   phonemizer.separatorr   r   phonemizer.utilsr   r   Backenddefault_marksrQ   boolintr8   r1   r4   r@   r9   r7   <module>rf      s    
			 



       1 1 1 1 1 1 1 1 1 1 1 1 % % % % % % ' ' ' ' ' ' / / / / / / D D D D D D A A A A A A ( ( ( ( ( ( . . . . . . = = = = = = = = / / / / / / / /
C
D
  #):"%*%*1J1J1L1L! %*6'/#ye yeye ye I&	ye
 ye ye #ye #ye !g.ye ye 49ye (ye %ye ye ye ye ye yex0B0B0B 490B 	0B
 (0B %0B 0B 0B 0Bf//CcN#/ / 	/
 / / #/ / / / / /r9   