a
    âñh`%  ã                   @   sð   d dl Z d dlZd dlmZmZmZmZ d dlZd dlm	Z	m
Z
mZ d dlmZ d dlmZ dZdZdZd	Zdddddddddddddddddddddddddddddd
œZee ee eeeeeeeef f dœdd„ZG dd„ deƒZdS )é    N)ÚListÚDictÚTupleÚOptional)Úextract_archiveÚunicode_csv_readerÚvalidate_file)ÚTensor)ÚDatasetZCommonVoiceÚenglishzcv-corpus-5.1-2020-06-22z	train.tsv)z"cv-corpus-5.1-2020-06-22/tt.tar.gzz"cv-corpus-5.1-2020-06-22/en.tar.gzz"cv-corpus-5.1-2020-06-22/de.tar.gzz"cv-corpus-5.1-2020-06-22/fr.tar.gzz"cv-corpus-5.1-2020-06-22/cy.tar.gzz"cv-corpus-5.1-2020-06-22/br.tar.gzz"cv-corpus-5.1-2020-06-22/cv.tar.gzz"cv-corpus-5.1-2020-06-22/tr.tar.gzz"cv-corpus-5.1-2020-06-22/ky.tar.gzz%cv-corpus-5.1-2020-06-22/ga-IE.tar.gzz#cv-corpus-5.1-2020-06-22/kab.tar.gzz"cv-corpus-5.1-2020-06-22/ca.tar.gzz%cv-corpus-5.1-2020-06-22/zh-TW.tar.gzz"cv-corpus-5.1-2020-06-22/sl.tar.gzz"cv-corpus-5.1-2020-06-22/it.tar.gzz"cv-corpus-5.1-2020-06-22/nl.tar.gzz#cv-corpus-5.1-2020-06-22/cnh.tar.gzz"cv-corpus-5.1-2020-06-22/eo.tar.gzz"cv-corpus-5.1-2020-06-22/et.tar.gzz"cv-corpus-5.1-2020-06-22/fa.tar.gzz"cv-corpus-5.1-2020-06-22/eu.tar.gzz"cv-corpus-5.1-2020-06-22/es.tar.gzz%cv-corpus-5.1-2020-06-22/zh-CN.tar.gzz"cv-corpus-5.1-2020-06-22/mn.tar.gzz#cv-corpus-5.1-2020-06-22/sah.tar.gzz"cv-corpus-5.1-2020-06-22/dv.tar.gzz"cv-corpus-5.1-2020-06-22/rw.tar.gzz%cv-corpus-5.1-2020-06-22/sv-SE.tar.gzz"cv-corpus-5.1-2020-06-22/ru.tar.gz)ÚlineÚheaderÚpathÚfolder_audioÚreturnc           	      C   sN   |d dksJ ‚| d }t j |||¡}t |¡\}}tt|| ƒƒ}|||fS )Né   r   )Úosr   ÚjoinÚ
torchaudioÚloadÚdictÚzip)	r   r   r   r   ZfileidÚfilenameZwaveformZsample_rateZdic© r   ú_/home/yuhw/wc/uboone-dl-vtx/venv/lib/python3.9/site-packages/torchaudio/datasets/commonvoice.pyÚload_commonvoice_item7   s    r   c                
   @   s~   e Zd ZdZdZdZdZedee	e
dfeeee eeeee ddœdd	„Zeeeeeeef f d
œdd„Zedœdd„ZdS )ÚCOMMONVOICEa  Create a Dataset for `CommonVoice <https://commonvoice.mozilla.org/>`_.

    Args:
        root (str): Path to the directory where the dataset is found or downloaded.
        tsv (str, optional): The name of the tsv file used to construct the metadata.
            (default: ``"train.tsv"``)
        url (str, optional): Deprecated.
        folder_in_archive (str, optional): The top-level directory of the dataset.
        version (str): Version string. (default: ``"cv-corpus-5.1-2020-06-22"``)
        language (str, optional): Language of the dataset. (default: None)
            The following values are mapped to their corresponding shortened version:
            ``"tatar"``, ``"english"``, ``"german"``,
            ``"french"``, ``"welsh"``, ``"breton"``, ``"chuvash"``, ``"turkish"``, ``"kyrgyz"``,
            ``"irish"``, ``"kabyle"``, ``"catalan"``, ``"taiwanese"``, ``"slovenian"``,
            ``"italian"``, ``"dutch"``, ``"hakha chin"``, ``"esperanto"``, ``"estonian"``,
            ``"persian"``, ``"portuguese"``, ``"basque"``, ``"spanish"``, ``"chinese"``,
            ``"mongolian"``, ``"sakha"``, ``"dhivehi"``, ``"kinyarwanda"``, ``"swedish"``,
            ``"russian"``, ``"indonesian"``, ``"arabic"``, ``"tamil"``, ``"interlingua"``,
            ``"latvian"``, ``"japanese"``, ``"votic"``, ``"abkhaz"``, ``"cantonese"`` and
            ``"romansh sursilvan"``.
            For the other allowed values, Please checkout https://commonvoice.mozilla.org/en/datasets.
        download (bool, optional): Deprecated.
    z.txtz.mp3ZclipsNF)ÚrootÚtsvÚurlÚfolder_in_archiveÚversionÚlanguageÚdownloadr   c              )   C   s  |du rt dƒ‚n|du r&t dt¡ |d ur:t dt¡ dddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.œ(}||v r¸d/}	|| }tj |||	 ¡}ntd0ƒ‚tj |¡}
tj ||
¡}|
 	d1d2¡d3 }
tj |||
¡}tj ||¡| _
tj | j
¡�s¢tj |¡�ršt |d ¡}|�r�tj |¡}t|d4ƒ�.}t||d5ƒ�spt d6|› d7�ƒ‚W d   ƒ n1 �s†0    Y  t|ƒ nt dƒ‚tj |||¡| _t| jd8ƒ�0}t|d9d:�}t|ƒ| _t|ƒ| _W d   ƒ n1 �sø0    Y  d S );NTz€The dataset is no longer publicly accessible. You need to download the archives externally and place them in the root directory.Fz_The use of the download flag is deprecated, since the dataset is no longer directly accessible.z­The use of the url flag is deprecated, since the dataset is no longer publicly accessible. To specify the language of the dataset, please use the language parameter instead.ÚttÚenÚdeÚfrÚcyÚbrZcvÚtrÚkyzga-IEZkabÚcazzh-TWÚslÚitÚnlZcnhÚeoÚetÚfaÚptÚeuÚeszzh-CNÚmnZsahZdvÚrwzsv-SEÚruÚidÚarÚtaÚiaÚlvÚjaZvotÚabzzh-HKz
rm-sursilv)(Ztatarr   ÚgermanÚfrenchZwelshZbretonZchuvashÚturkishZkyrgyzZirishZkabyleÚcatalanZ	taiwaneseÚ	slovenianÚitalianÚdutchz
hakha chinZ	esperantoÚestonianZpersianÚ
portugueseZbasqueÚspanishÚchineseZ	mongolianZsakhaZdhivehiZkinyarwandaÚswedishÚrussianZ
indonesianÚarabicZtamilZinterlinguaZlatvianÚjapaneseZvoticZabkhazZ	cantonesezromansh sursilvanz.tar.gza  Allowed language values are ``"tatar"``, ``"english"``, ``"german"``,``"french"``, ``"welsh"``, ``"breton"``, ``"chuvash"``, ``"turkish"``, ``"kyrgyz"``,``"irish"``, ``"kabyle"``, ``"catalan"``, ``"taiwanese"``, ``"slovenian"``,``"italian"``, ``"dutch"``, ``"hakha chin"``, ``"esperanto"``, ``"estonian"``,``"persian"``, ``"portuguese"``, ``"basque"``, ``"spanish"``, ``"chinese"``,``"mongolian"``, ``"sakha"``, ``"dhivehi"``, ``"kinyarwanda"``, ``"swedish"``,``"russian"``, ``"indonesian"``, ``"arabic"``, ``"tamil"``, ``"interlingua"``,``"latvian"``, ``"japanese"``, ``"votic"``, ``"abkhaz"``, ``"cantonese"`` and``"romansh sursilvan"``.Ú.é   r   ÚrbÚsha256zThe hash of z4 does not match. Delete the file manually and retry.Úrú	)Ú	delimiter)ÚRuntimeErrorÚwarningsÚwarnÚRuntimeWarningr   r   r   Ú
ValueErrorÚbasenameÚrsplitÚ_pathÚisdirÚisfileÚ
_CHECKSUMSÚgetÚopenr   r   Z_tsvr   ÚnextÚ_headerÚlistÚ_walker)Úselfr   r   r   r    r!   r"   r#   Ú	languagesZext_archiver[   ÚarchiveZchecksumÚfilepathZfile_objÚwalkerr   r   r   Ú__init__g   s¬    	ÿþýØ+ÿ
ÿ$
ÿ
zCOMMONVOICE.__init__)Únr   c                 C   s   | j | }t|| 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, dictionary)``,  where dictionary is built
            from the TSV file with the following keys: ``client_id``, ``path``, ``sentence``,
            ``up_votes``, ``down_votes``, ``age``, ``gender`` and ``accent``.
        )rf   r   rd   r]   Ú_folder_audio)rg   rm   r   r   r   r   Ú__getitem__à   s    
zCOMMONVOICE.__getitem__)r   c                 C   s
   t | jƒS )N)Úlenrf   )rg   r   r   r   Ú__len__î   s    zCOMMONVOICE.__len__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Z_ext_txtZ
_ext_audiorn   ÚTSVÚFOLDER_IN_ARCHIVEÚVERSIONÚLANGUAGEÚstrr   Úboolrl   Úintr   r	   r   ro   rq   r   r   r   r   r   J   s*   ùùy"r   )r   rW   Útypingr   r   r   r   r   Ztorchaudio.datasets.utilsr   r   r   Ztorchr	   Ztorch.utils.datar
   rw   ry   rx   rv   r`   rz   r|   r   r   r   r   r   r   Ú<module>   s\   
ã!ý