
    rHJj[              	          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y)z-Provides utility functions for the phonemizer    N)Number)Path)UnionListTupleIterableiterablereturnc                 H    g }d}| D ]  }||z  }|j                  |        |S )z6Returns the cumulative sum of the `iterable` as a listr   )append)r	   res
cumulativevalues       Z/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/phonemizer/utils.pycumsumr      s3    
CJe


:  J    textc                     t        | t              r<| j                  t        j                        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   #   s3    $zz"**%++BJJ77Kr   c                 d    t        | t              r| S t        j                  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                 R   t        |       } t        t        dt        |       |z              }t	        |t        |             }t        |dz
        D cg c]  }| ||z  |dz   |z    }}| |dz
  |z  d }|r|j                  |       dgt        d |dd D              z   }||fS c c}w )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

       Nr   c              3   2   K   | ]  }t        |        y wN)len).0cs     r   	<genexpr>zchunks.<locals>.<genexpr>V   s     =,<qCF,<   )r   intmaxr%   minranger   r   )r   r    sizenchunksitext_chunkslastoffsetss           r   chunksr5   1   s    4 tnDs1c$i#o&'D#s4y!G 05Wq[/AC/A!QXq1un%/A  C 1$%&D4 cF=K,<=>>GCs   B$pathc                 >   	 t         j                  j                  d      dz  | z  } | j                         st        d|        | j                         S # t        $ r> t         j                  j	                  dd      5 }|| z  } ddd       n# 1 sw Y   nxY wY tw xY w)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AttributeErrorr6   exists
ValueErrorresolve)r6   r9   s     r   get_package_resourcerA   Z   s    * ""((6@4G
 ;;=B4&IJJ<<>     %%lG<4<D =<< s)   %A )B>B	BB	BBversion.c                 d    t        d | j                  dd      j                  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   2   K   | ]  }t        |        y wr$   )r+   )r&   vs     r   r(   z#version_as_tuple.<locals>.<genexpr>   s     H!GAQ!Gr)   z-dev .)tuplereplacer   )rB   s    r   version_as_tuplerJ   |   s+     H!<!B!B3!GHHHr   )__doc__r   numbersr   pathlibr   typingr   r   r   r   r:   r   r   r   r   r+   r5   rA   rJ    r   r   <module>rP      s    4 	   / / Xf% $v, 5d3i( T#Y !5d3i( !S !& sDI~& & S & d3i$s)+,& Rs t DIc IeCHo Ir   