o
    ôjf  ã                   @   s�   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dœZh d	£Zd
ee dedee fdd„ZG dd„ de
ƒZdS )é    N)ÚPath)ÚIterableÚListÚTupleÚUnion)ÚDataset)Údownload_url_to_fileZ@209a8b4cd265013e96f4658632a9878103b0c5abf62b50d4ef3ae1be226b29e4Z@408ccaae803641c6d7b626b6299949320c2dbca96b2220fd3fb17887b023b027)úBhttp://svn.code.sf.net/p/cmusphinx/code/trunk/cmudict/cmudict-0.7búJhttp://svn.code.sf.net/p/cmusphinx/code/trunk/cmudict/cmudict-0.7b.symbols>8   z?QUESTION-MARKz.DECIMALz)CLOSE-PARENTHESESz;SEMI-COLON(1)z"UNQUOTEz)PARENz!EXCLAMATION-POINTz(BEGIN-PARENSz(IN-PARENTHESESz-DASHz.PERIODz{OPEN-BRACEz}RIGHT-BRACEz+PLUSz)CLOSE-PARENz)UN-PARENTHESESz}CLOSE-BRACEz
)END-PARENz,COMMAz'END-INNER-QUOTEz#POUND-SIGNz--DASHz
#HASH-MARKz.DOTz.POINTz
"IN-QUOTESz(OPEN-PARENTHESESz#SHARP-SIGNz{LEFT-BRACEz
'END-QUOTEz:COLONz)END-PARENTHESESz)END-THE-PARENz'QUOTEz(LEFT-PARENz'SINGLE-QUOTEz'INNER-QUOTEz(PARENSz-HYPHENz"END-OF-QUOTEz{BRACEz)PARENSz)RIGHT-PARENz(PARENz"DOUBLE-QUOTEz
"END-QUOTEz%PERCENTz(PARENTHESESz
.FULL-STOPz"CLOSE-QUOTEz...ELLIPSISz;SEMI-COLONz
&AMPERSANDz)END-PARENSz/SLASHz"QUOTEÚlinesÚexclude_punctuationsÚreturnc                 C   sš   t  d¡}g }| D ]A}|r| d¡rq	| ¡  d¡\}}|tv r7|r#q	| d¡r+d}n| d¡r3d}n|d }t  |d|¡}| d¡}| ||f¡ q	|S )	Nz
\([0-9]+\)z;;;z  z...z--r   Ú ú )ÚreÚcompileÚ
startswithÚstripÚsplitÚ_PUNCTUATIONSÚsubÚappend)r   r   Z_alt_reÚcmudictÚlineÚwordZphones© r   úl/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torchaudio/datasets/cmudict.pyÚ_parse_dictionaryJ   s$   



r   c                   @   sŠ   e Zd ZdZ	dddddœdeeef ded	ed
ededdfdd„Zde	de
eee f fdd„Zde	fdd„Zedee fdd„ƒZdS )ÚCMUDictaZ  *CMU Pronouncing Dictionary* :cite:`cmudict` (CMUDict) dataset.

    Args:
        root (str or Path): Path to the directory where the dataset is found or downloaded.
        exclude_punctuations (bool, optional):
            When enabled, exclude the pronounciation of punctuations, such as
            `!EXCLAMATION-POINT` and `#HASH-MARK`.
        download (bool, optional):
            Whether to download the dataset if it is not found at root path. (default: ``False``).
        url (str, optional):
            The URL to download the dictionary from.
            (default: ``"http://svn.code.sf.net/p/cmusphinx/code/trunk/cmudict/cmudict-0.7b"``)
        url_symbols (str, optional):
            The URL to download the list of symbols from.
            (default: ``"http://svn.code.sf.net/p/cmusphinx/code/trunk/cmudict/cmudict-0.7b.symbols"``)
    TFr	   r
   )ÚdownloadÚurlÚurl_symbolsÚrootr   r   r    r!   r   Nc          
      C   sB  || _ t|ƒ| _tj | j¡std|› �ƒ‚| jtj |¡ }| jtj |¡ }tj |¡sC|s7td|› �ƒ‚t	 
|d ¡}t|||ƒ tj |¡s^|sRtd|› �ƒ‚t	 
|d ¡}t|||ƒ t|dƒ�}	dd„ |	 ¡ D ƒ| _W d   ƒ n1 sxw   Y  t|ddd��}	t|	 ¡ | j d	�| _W d   ƒ d S 1 sšw   Y  d S )
Nz#The root directory does not exist; z`The dictionary file is not found in the following location. Set `download=True` to download it. z\The symbol file is not found in the following location. Set `download=True` to download it. Úrc                 S   s   g | ]}|  ¡ ‘qS r   )r   )Ú.0r   r   r   r   Ú
<listcomp>Ÿ   s    z$CMUDict.__init__.<locals>.<listcomp>zlatin-1)Úencoding)r   )r   r   Z
_root_pathÚosÚpathÚisdirÚRuntimeErrorÚbasenameÚexistsÚ
_CHECKSUMSÚgetr   ÚopenÚ	readlinesÚ_symbolsr   Ú_dictionary)
Úselfr"   r   r   r    r!   Z	dict_fileZsymbol_fileÚchecksumÚtextr   r   r   Ú__init__{   s<   

ÿÿÿÿÿ"ÿzCMUDict.__init__Únc                 C   s
   | j | S )a  Load the n-th sample from the dataset.

        Args:
            n (int): The index of the sample to be loaded.

        Returns:
            Tuple of a word and its phonemes

            str:
                Word
            List[str]:
                Phonemes
        )r2   )r3   r7   r   r   r   Ú__getitem__¤   s   
zCMUDict.__getitem__c                 C   s
   t | jƒS )N)Úlenr2   ©r3   r   r   r   Ú__len__´   s   
zCMUDict.__len__c                 C   s
   | j  ¡ S )zLlist[str]: A list of phonemes symbols, such as ``"AA"``, ``"AE"``, ``"AH"``.)r1   Úcopyr:   r   r   r   Úsymbols·   s   
zCMUDict.symbols)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústrr   Úboolr6   Úintr   r   r8   r;   Úpropertyr=   r   r   r   r   r   i   s0    ýù
þýûúù
ø)r   )r'   r   Úpathlibr   Útypingr   r   r   r   Útorch.utils.datar   Ztorchaudio._internalr   r-   r   rB   rC   r   r   r   r   r   r   Ú<module>   s    þ<