o
    ôj¤  ã                   @   sÎ   d dl Z d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZ dZd	Zd
Zg d¢ZddddddddœZdd„ Zdededededed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Ú_load_waveformútrain-clean-100ZLibriSpeechi€>  )z	dev-cleanz	dev-otherz
test-cleanz
test-otherr
   ztrain-clean-360ztrain-other-500Z@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.gzc                 C   s^   d}d}|| }t j | |¡}t j ||¡}t j |¡s)t |d ¡}t|||d� t|ƒ d S )Nz$http://www.openslr.org/resources/12/z.tar.gz)Úhash_prefix)ÚosÚpathÚjoinÚisfileÚ
_CHECKSUMSÚgetr   r   )ÚrootÚurlÚbase_urlÚext_archiveÚfilenameÚarchiveZdownload_urlÚchecksum© r   úp/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torchaudio/datasets/librispeech.pyÚ_download_librispeech!   s   r   Úfileidr   ÚfolderÚ	ext_audioÚext_txtÚreturnc                 C   sà   |   d¡\}}}|› d|› d|› �}tj ||||› |› �¡}	|› d|› |› �}
tj |||||
¡}
t|
ƒ�$}|D ]}| ¡   dd¡\}}||krK nq9td|› �ƒ‚W d   ƒ n1 s]w   Y  |	t|t|ƒt|ƒt|ƒfS )Nú-ú é   zTranslation not found for )	Úsplitr   r   r   ÚopenÚstripÚFileNotFoundErrorÚSAMPLE_RATEÚint)r   r   r   r   r   Ú
speaker_idZ
chapter_idÚutterance_idZfileid_audioÚfilepathZ	file_textÚftÚlineZfileid_textÚ
transcriptr   r   r   Ú_get_librispeech_metadata.   s*   
ÿýü
úr0   c                   @   s˜   e 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f fdd„Zded	eeee	eeef fdd„Zd	efdd„Zd
S )ÚLIBRISPEECHaõ  *LibriSpeech* :cite:`7178964` 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: ``"LibriSpeech"``)
        download (bool, optional):
            Whether to download the dataset if it is not found at root path. (default: ``False``).
    z
.trans.txtz.flacFr   r   Úfolder_in_archiveÚdownloadr    Nc                 C   sª   || _ |tvrtd|› dt› d�ƒ‚t |¡}tj ||¡| _tj |||¡| _tj 	| j¡s@|r7t
||ƒ n	td| j› d�ƒ‚tdd„ t| jƒ d| j ¡D ƒƒ| _d S )	NzInvalid url 'z' given; please provide one of Ú.zDataset not found at z5. Please set `download=True` to download the dataset.c                 s   s   � | ]}t |jƒV  qd S ©N)ÚstrÚstem)Ú.0Úpr   r   r   Ú	<genexpr>w   s   € z'LIBRISPEECH.__init__.<locals>.<genexpr>z*/*/*)Ú_urlÚ_DATA_SUBSETSÚ
ValueErrorr   Úfspathr   r   Ú_archiveÚ_pathÚisdirr   ÚRuntimeErrorÚsortedr   ÚglobÚ
_ext_audioÚ_walker)Úselfr   r   r2   r3   r   r   r   Ú__init__`   s   
ÿ*zLIBRISPEECH.__init__Únc                 C   s"   | j | }t|| j| j| j| jƒS )a>  Get metadata for the n-th sample from the dataset. Returns filepath instead of waveform,
        but otherwise returns the same fields as :py:func:`__getitem__`.

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

        Returns:
            Tuple of the following items;

            str:
                Path to audio
            int:
                Sample rate
            str:
                Transcript
            int:
                Speaker ID
            int:
                Chapter ID
            int:
                Utterance ID
        )rF   r0   r?   r;   rE   Ú_ext_txt)rG   rI   r   r   r   r   Úget_metadatay   s   
zLIBRISPEECH.get_metadatac                 C   s2   |   |¡}t| j|d |d ƒ}|f|dd…  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:
                Transcript
            int:
                Speaker ID
            int:
                Chapter ID
            int:
                Utterance ID
        r   r#   N)rK   r	   r?   )rG   rI   ÚmetadataÚwaveformr   r   r   Ú__getitem__“   s   
zLIBRISPEECH.__getitem__c                 C   s
   t | jƒS r5   )ÚlenrF   )rG   r   r   r   Ú__len__­   s   
zLIBRISPEECH.__len__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rJ   rE   ÚURLÚFOLDER_IN_ARCHIVEr   r6   r   ÚboolrH   r)   r   rK   r   rN   rP   r   r   r   r   r1   M   s*    û
þýüû
ú""r1   )r   Úpathlibr   Útypingr   r   Útorchr   Útorch.utils.datar   Útorchaudio._internalr   Útorchaudio.datasets.utilsr   r	   rU   rV   r(   r<   r   r   r6   r)   r0   r1   r   r   r   r   Ú<module>   sD    
ùÿÿÿÿÿ
þ