a
    âñhç  ã                   @   s¢   d dl Z d dlmZ d dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZ dZdZdd	d
dddddœZeeeeeeeeeeeeef dœdd„ZG dd„ deƒZdS )é    N)ÚTuple)ÚTensor)ÚDataset)Údownload_urlÚextract_archiveÚ
walk_filesútrain-clean-100ZLibriTTSZ 0c3076c1e5245bb3f0af7d82087ee207Z 815555d8d75995782ac3ccd7f047213dZ 7bed3bdb047c4c197f1ad3bc412db59fZ ae3258249472a13b5abef2a816f733e4Z 4a8c202b78fe1bc0c47916a98f3a2ea8Z a84ef10ddade5fd25df69596a2767b2dZ 7b181dd5ace343a5f38427999684aa6f)z*http://www.openslr.org/60/dev-clean.tar.gzz*http://www.openslr.org/60/dev-other.tar.gzz+http://www.openslr.org/60/test-clean.tar.gzz+http://www.openslr.org/60/test-other.tar.gzz0http://www.openslr.org/60/train-clean-100.tar.gzz0http://www.openslr.org/60/train-clean-360.tar.gzz0http://www.openslr.org/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 s˜0    Y  t|	dƒ�}| ¡ }	W d   ƒ n1 sÊ0    Y  |||
|	t|ƒt|ƒ|fS )NÚ_Úr)	ÚsplitÚosr
   ÚjoinÚ
torchaudioÚloadÚopenÚreadlineÚint)r	   r
   r   r   r   Z
speaker_idZ
chapter_idZ
segment_idZutterance_idZnormalized_textZoriginal_textZ
file_audioZwaveformZsample_rateÚft© r   ú\/home/yuhw/wc/uboone-dl-vtx/venv/lib/python3.9/site-packages/torchaudio/datasets/libritts.pyÚload_libritts_item   s*    
&&ùr   c                	   @   sj   e Zd ZdZdZdZdZeedfe	e	e	e
ddœdd	„Zeeeee	e	eee	f d
œdd„Zedœdd„ZdS )ÚLIBRITTSaâ  Create a Dataset for LibriTTS.

    Args:
        root (str): 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.wavFN)ÚrootÚurlÚfolder_in_archiveÚdownloadr   c                 C   sÊ   |dv r"d}d}t j ||| ¡}t j |¡}t j ||¡}| d¡d }t j ||¡}t j ||¡| _|r¨t j | j¡s¨t j |¡s t 	|d ¡}	t
|||	d� t|ƒ t| j| jddd	�}
t|
ƒ| _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   )Z
hash_valueFT)ÚsuffixÚprefixZremove_suffix)r   r
   r   Úbasenamer   Ú_pathÚisdirÚisfileÚ
_CHECKSUMSÚgetr   r   r   Ú
_ext_audioÚlistÚ_walker)Úselfr   r   r    r!   Zext_archiveÚbase_urlr%   ÚarchiveZchecksumÚwalkerr   r   r   Ú__init__W   s&    
ÿzLIBRITTS.__init__)Únr   c                 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: ``(waveform, sample_rate, original_text, normalized_text, speaker_id,
            chapter_id, utterance_id)``
        )r-   r   r&   r+   Ú_ext_original_txtÚ_ext_normalized_txt)r.   r3   r	   r   r   r   Ú__getitem__‚   s    

ûzLIBRITTS.__getitem__)r   c                 C   s
   t | jƒS )N)Úlenr-   )r.   r   r   r   Ú__len__•   s    zLIBRITTS.__len__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r4   r5   r+   ÚURLÚFOLDER_IN_ARCHIVEÚstrÚboolr2   r   r   r   r6   r8   r   r   r   r   r   C   s    ûú+"r   )r   Útypingr   r   Ztorchr   Ztorch.utils.datar   Ztorchaudio.datasets.utilsr   r   r   r=   r>   r)   r?   r   r   r   r   r   r   r   Ú<module>   s.   ùú)