
    Pi[              	       j   d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	m
Z
 ddlZde
e         dee         fdZd	eeee         f         dee         fd
Zd	eeee         f         defdZd	eeee         f         dede	eee                  ee         f         fdZdedefdZdede	edf         fdZdS )z-Provides utility functions for the phonemizer    N)Number)Path)UnionListTupleIterableiterablereturnc                 L    g }d}| D ]}||z  }|                     |           |S )z6Returns the cumulative sum of the `iterable` as a listr   )append)r	   res
cumulativevalues       d/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/phonemizer/utils.pycumsumr      s?    
CJ  e


:J    textc                     t          | t                    r<|                     t          j                                      t          j                  S | S )z8Returns the string `text` as a list of lines, split by 
)
isinstancestrstriposlinesepsplitr   s    r   str2listr   #   s=    $ 8zz"*%%++BJ777Kr   c                 n    t          | t                    r| S t          j                            |           S )zBReturns the list of lines `text` as a single string separated by 
)r   r   r   r   joinr   s    r   list2strr   *   s-    $ :??4   r   numc                     t                      t          t          dt                     |z                      t	          |t                               } fdt          |dz
            D             } |dz
  z  d         }|r|                    |           dgt          d |dd         D                       z   }||fS )a  Return a maximum of `num` equally sized chunks of a `text`

    This method is usefull when phonemizing a single text on multiple jobs.

    The exact number of chunks returned is `m = min(num, len(str2list(text)))`.
    Only the m-1 first chunks have equal size. The last chunk can be longer.
    The input `text` can be a list or a string. Return a list of `m` strings.

    Parameters
    ----------
    text (str or list) : The text to divide in chunks

    num (int) : The number of chunks to build, must be a strictly positive
    integer.

    Returns
    -------
    chunks (list of list of str) : The chunked text with utterances separated
        by '
'.

    offsets (list of int) : offset used below to recover the line numbers in
        the input text wrt the chunks

       c                 6    g | ]}|z  |d z   z           S )r"    ).0isizer   s     r   
<listcomp>zchunks.<locals>.<listcomp>O   sB     C C C*+QXq1un$%C C Cr   Nr   c              3   4   K   | ]}t          |          V  d S N)len)r%   cs     r   	<genexpr>zchunks.<locals>.<genexpr>V   s(      ==qCFF======r   )r   intmaxr+   minranger   r   )r   r    nchunkstext_chunkslastoffsetsr'   s   `     @r   chunksr7   1   s    4 tnnDs1c$ii#o&&''D#s4yy!!GC C C C C/4Wq[/A/AC C CK 1$%%&D !4   cF==K,<===>>>Gr   pathc                 ^   	 t           j                            d          dz  | z  } nM# t          $ r@ t           j                            dd          5 }|| z  } ddd           n# 1 swxY w Y   Y nw xY w|                                 st          d|            |                                 S )a;  Returns the absolute path to a phonemizer resource file or directory

    The packages resource are stored within the source tree in the
    'phonemizer/share' directory and, once the package is installed, are moved
    to another system directory (e.g. /share/phonemizer).

    Parameters
    ----------
    path (str) : the file or directory to get, must be relative to
        'phonemizer/share'.

    Raises
    ------
    ValueError if the required `path` is not found

    Returns
    -------
    The absolute path to the required resource as a `pathlib.Path`

    
phonemizershareNz'the requested resource does not exist: )	importlib	resourcesfilesAttributeErrorr8   exists
ValueErrorresolve)r8   r;   s     r   get_package_resourcerC   Z   s    * "((66@4G       %%lG<< 	 4<D	  	  	  	  	  	  	  	  	  	  	  	  	  	  	   ;;== KI4IIJJJ<<>>s3   %( *A2A$A2$A(	(A2+A(	,A21A2version.c                     t          d |                     dd                              d          D                       S )zReturns a tuple of integers from a version string

    Any '-dev' in version string is ignored. For instance, returns (1, 2, 3)
    from '1.2.3' or (0, 2) from '0.2-dev'

    c              3   4   K   | ]}t          |          V  d S r*   )r/   )r%   vs     r   r-   z#version_as_tuple.<locals>.<genexpr>   s(      HHAQHHHHHHr   z-dev .)tuplereplacer   )rD   s    r   version_as_tuplerL   |   s=     HH!<!<!B!B3!G!GHHHHHHr   )__doc__r   numbersr   pathlibr   typingr   r   r   r   r<   r   r   r   r   r/   r7   rC   rL   r$   r   r   <module>rQ      s   4 3 				             / / / / / / / / / / / /    Xf% $v,    5d3i( T#Y    !5d3i( !S ! ! ! !& sDI~& & S & d3i$s)+,&  &  &  & Rs t    DIc IeCHo I I I I I Ir   