o
    ôjî  ã                   @   sÀ   d dl Z d dlmZ d dlmZmZ d dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ dZd	Zd
dddddddœZdedededededeeeeeeeef fdd„ZG dd„ de
ƒZdS )é    N)ÚPath)ÚTupleÚUnion)ÚTensor)ÚDataset)Údownload_url_to_file)Ú_extract_tarútrain-clean-100ZLibriTTSZ@da0864e1bd26debed35da8a869dd5c04dfc27682921936de7cff9c8a254dbe1aZ@d413eda26f3a152ac7c9cf3658ef85504dfb1b625296e5fa83727f5186cca79cZ@234ea5b25859102a87024a4b9b86641f5b5aaaf1197335c95090cde04fe9a4f5Z@33a5342094f3bba7ccc2e0500b9e72d558f72eb99328ac8debe1d9080402f10dZ@c5608bf1ef74bb621935382b8399c5cdd51cd3ee47cec51f00f885a64c6c7f6bZ@ce7cff44dcac46009d18379f37ef36551123a1dc4e5c8e4eb73ae57260de4886Z@e35f7e34deeb2e2bdfe4403d88c8fdd5fbf64865cae41f027a185a6965f0a5df)z4http://www.openslr.org/resources/60/dev-clean.tar.gzz4http://www.openslr.org/resources/60/dev-other.tar.gzz5http://www.openslr.org/resources/60/test-clean.tar.gzz5http://www.openslr.org/resources/60/test-other.tar.gzz:http://www.openslr.org/resources/60/train-clean-100.tar.gzz:http://www.openslr.org/resources/60/train-clean-360.tar.gzz:http://www.openslr.org/resources/60/train-other-500.tar.gzÚfileidÚpathÚ	ext_audioÚext_original_txtÚext_normalized_txtÚreturnc                 C   sî   |   d¡\}}}}| }|| }	tj ||||	¡}	|| }
tj ||||
¡}
|| }tj ||||¡}t |¡\}}t|
ƒ�}| ¡ }
W d   ƒ n1 sLw   Y  t|	dƒ�}| ¡ }	W d   ƒ n1 sew   Y  |||
|	t|ƒt|ƒ|fS )NÚ_Úr)	ÚsplitÚosr   ÚjoinÚ
torchaudioÚloadÚopenÚreadlineÚint)r
   r   r   r   r   Ú
speaker_idÚ
chapter_idZ
segment_idÚutterance_idZnormalized_textZoriginal_textÚ
file_audioÚwaveformÚsample_rateÚft© r!   úo/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/torchaudio/datasets/libritts.pyÚload_libritts_item   s.   

ÿ
ÿùr#   c                   @   s|   e Zd ZdZdZdZdZeedfde	e
ef de
de
d	ed
df
dd„Zded
eeee
e
eee
f fdd„Zd
efdd„ZdS )ÚLIBRITTSaù  *LibriTTS* :cite:`Zen2019LibriTTSAC` dataset.

    Args:
        root (str or Path): Path to the directory where the dataset is found or downloaded.
        url (str, optional): The URL to download the dataset from,
            or the type of the dataset to dowload.
            Allowed type values are ``"dev-clean"``, ``"dev-other"``, ``"test-clean"``,
            ``"test-other"``, ``"train-clean-100"``, ``"train-clean-360"`` and
            ``"train-other-500"``. (default: ``"train-clean-100"``)
        folder_in_archive (str, optional):
            The top-level directory of the dataset. (default: ``"LibriTTS"``)
        download (bool, optional):
            Whether to download the dataset if it is not found at root path. (default: ``False``).
    z.original.txtz.normalized.txtz.wavFÚrootÚurlÚfolder_in_archiveÚdownloadr   Nc           
      C   sþ   |dv rd}d}t j ||| ¡}t  |¡}t j |¡}t j ||¡}| d¡d }t j ||¡}t j ||¡| _|rZt j | j¡sYt j |¡sUt	 
|d ¡}	t|||	d� t|ƒ nt j | j¡sjtd| j› d�ƒ‚td	d
„ t| jƒ d| j ¡D ƒƒ| _d S )N)z	dev-cleanz	dev-otherz
test-cleanz
test-otherr	   ztrain-clean-360ztrain-other-500z.tar.gzz$http://www.openslr.org/resources/60/Ú.r   )Úhash_prefixz	The path zT doesn't exist. Please check the ``root`` path or set `download=True` to download itc                 s   s   � | ]}t |jƒV  qd S ©N)ÚstrÚstem)Ú.0Úpr!   r!   r"   Ú	<genexpr>„   s   € z$LIBRITTS.__init__.<locals>.<genexpr>z*/*/*)r   r   r   ÚfspathÚbasenamer   Ú_pathÚisdirÚisfileÚ
_CHECKSUMSÚgetr   r   ÚexistsÚRuntimeErrorÚsortedr   ÚglobÚ
_ext_audioÚ_walker)
Úselfr%   r&   r'   r(   Úext_archiveÚbase_urlr2   ÚarchiveÚchecksumr!   r!   r"   Ú__init__U   s,   

€ÿ*zLIBRITTS.__init__Únc                 C   s"   | j | }t|| j| j| j| 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 the following items;

            Tensor:
                Waveform
            int:
                Sample rate
            str:
                Original text
            str:
                Normalized text
            int:
                Speaker ID
            int:
                Chapter ID
            str:
                Utterance ID
        )r=   r#   r3   r<   Ú_ext_original_txtÚ_ext_normalized_txt)r>   rD   r
   r!   r!   r"   Ú__getitem__†   s   
ûzLIBRITTS.__getitem__c                 C   s
   t | jƒS r+   )Úlenr=   )r>   r!   r!   r"   Ú__len__§   s   
zLIBRITTS.__len__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rE   rF   r<   ÚURLÚFOLDER_IN_ARCHIVEr   r,   r   ÚboolrC   r   r   r   rG   rI   r!   r!   r!   r"   r$   A   s*    û
þýüû
ú$1!r$   )r   Úpathlibr   Útypingr   r   r   Útorchr   Útorch.utils.datar   Ztorchaudio._internalr   Útorchaudio.datasets.utilsr   rN   rO   r6   r,   r   r#   r$   r!   r!   r!   r"   Ú<module>   s@    ùÿþýüû
ú)