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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LibriSpeechZ@76f87d090650617fca0cac8f88b9416e0ebf80350acb97b343a85fa903728ab3Z@12661c48e8c3fe1de2c1caa4c3e135193bfb1811584f11f569dd12645aa84365Z@39fde525e59672dc6d1551919b1478f724438a95aa55f874b576be21967e6c23Z@d09c181bba5cf717b3dee7d4d592af11a3ee3a09e08ae025c5506f6ebe961c29Z@d4ddd1d5a6ab303066f14971d768ee43278a5f2a0aa43dc716b0e64ecbbbf6e2Z@146a56496217e96c14334a160df97fffedd6e0a04e66b9c5af0d40be3c792ecfZ@ddb22f27f96ec163645d53215559df6aa36515f26e01dd70798188350adcb6d2)z4http://www.openslr.org/resources/12/dev-clean.tar.gzz4http://www.openslr.org/resources/12/dev-other.tar.gzz5http://www.openslr.org/resources/12/test-clean.tar.gzz5http://www.openslr.org/resources/12/test-other.tar.gzz:http://www.openslr.org/resources/12/train-clean-100.tar.gzz:http://www.openslr.org/resources/12/train-clean-360.tar.gzz:http://www.openslr.org/resources/12/train-other-500.tar.gz)ÚfileidÚpathÚ	ext_audioÚext_txtÚreturnc                 C   sè   |   d¡\}}}|d | | }tj ||||¡}|d | d | }|| }	tj ||||	¡}	t |	¡\}
}t|ƒ�F}|D ]$}| ¡   dd¡\}}||kr| q®q|td| ƒ‚W d   ƒ n1 sÂ0    Y  |
||t	|ƒt	|ƒt	|ƒfS )Nú-ú é   zTranslation not found for )
ÚsplitÚosr
   ÚjoinÚ
torchaudioÚloadÚopenÚstripÚFileNotFoundErrorÚint)r	   r
   r   r   Z
speaker_idZ
chapter_idZutterance_idZ	file_textZfileid_audioZ
file_audioZwaveformZsample_rateÚftÚlineZfileid_textZ	utterance© r   ú_/home/yuhw/wc/uboone-dl-vtx/venv/lib/python3.9/site-packages/torchaudio/datasets/librispeech.pyÚload_librispeech_item!   s(    
*úr   c                   @   sd   e 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f d	œd
d„Zedœdd„ZdS )ÚLIBRISPEECHaè  Create a Dataset for LibriSpeech.

    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: ``"LibriSpeech"``)
        download (bool, optional):
            Whether to download the dataset if it is not found at root path. (default: ``False``).
    z
.trans.txtz.flacFN)Ú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/12/Ú.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__X   s&    
ÿzLIBRISPEECH.__init__)Únr   c                 C   s   | j | }t|| j| j| jƒS )zêLoad the n-th sample from the dataset.

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

        Returns:
            tuple: ``(waveform, sample_rate, utterance, speaker_id, chapter_id, utterance_id)``
        )r/   r   r(   r-   Ú_ext_txt)r0   r5   r	   r   r   r   Ú__getitem__�   s    	
zLIBRISPEECH.__getitem__)r   c                 C   s
   t | jƒS )N)Úlenr/   )r0   r   r   r   Ú__len__�   s    zLIBRISPEECH.__len__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r6   r-   ÚURLÚFOLDER_IN_ARCHIVEÚstrÚboolr4   r   r   r   r7   r9   r   r   r   r   r   E   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*   òý$