o
    ôj�  ã                   @   s~   d dl Z d dlmZ d dlmZmZmZmZ d dlZd dl	m
Z
 d dlmZ dZg d¢Zded	efd
d„ZG dd„ de
ƒZdS )é    N)ÚPath)ÚListÚOptionalÚTupleÚUnion)ÚDataset)Ú_load_waveformi€>  )ZAditiZAmyZBrianZEmmaZGeraintZIvyZJoannaZJoeyZJustinZKendraZKimberlyZMatthewZNicoleZRaveenaZRussellZSalliÚfileÚsubsetc           
      C   sÄ   i }t | dƒ�Q}|D ]E}| ¡  d¡}|d }d |dd… ¡ d¡\}}d | d¡dd… ¡}d | d¡dd… ¡}| d¡d }	||v rO|||	f||< q
W d  ƒ |S 1 s[w   Y  |S )u¬  Load transcirpt, iob, and intent labels for all utterances.

    Args:
        file (Path): The path to the label file.
        subset (str): Subset of the dataset to use. Options: [``"train"``, ``"valid"``, ``"test"``].

    Returns:
        Dictionary of labels, where the key is the filename of the audio,
            and the label is a Tuple of transcript, Insideâ€“outsideâ€“beginning (IOB) label, and intention label.
    Úrú r   é   Nú	éÿÿÿÿ)ÚopenÚstripÚsplitÚjoin)
r	   r
   ÚlabelsÚfÚlineÚindexÚtransZ
iob_intentÚiobÚintent© r   új/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torchaudio/datasets/snips.pyÚ_load_labels   s"   €ø
ÿ
ö
r   c                   @   s˜   e Zd ZdZdZ		ddeeef dedee	e  ded	df
d
d„Z
ded	eeeeeef fdd„Zded	eejeeeef fdd„Zd	efdd„ZdS )ÚSnipsa,  *Snips* :cite:`coucke2018snips` dataset.

    Args:
        root (str or Path): Root directory where the dataset's top level directory is found.
        subset (str): Subset of the dataset to use. Options: [``"train"``, ``"valid"``, ``"test"``].
        speakers (List[str] or None, optional): The speaker list to include in the dataset. If ``None``,
            include all speakers in the subset. (Default: ``None``)
        audio_format (str, optional): The extension of the audios. Options: [``"mp3"``, ``"wav"``].
            (Default: ``"mp3"``)
    zall.iob.snips.txtNÚmp3Úrootr
   ÚspeakersÚaudio_formatÚreturnc           	      C   sÒ   |dvrt dƒ‚|dvrt dƒ‚t|ƒ}|d | _| j| | _|d u r%t}tj | j¡s0tdƒ‚| j 	d|› �¡| _
g | _t| j
ƒD ]}t|jƒ}| d¡d	 }||v rZ| j |¡ qB| j| j }t||ƒ| _d S )
N)ÚtrainÚvalidÚtestz3`subset` must be one of ["train", "valid", "test"].)r   Úwavz,`audio_format` must be one of ["mp3", "wav].ZSNIPSzDataset not found.z*.ú-r   )Ú
ValueErrorr   Ú_pathÚ
audio_pathÚ	_SPEAKERSÚosÚpathÚisdirÚRuntimeErrorÚglobÚaudio_pathsÚdataÚsortedÚstrÚnamer   ÚappendÚ_trans_filer   r   )	Úselfr    r
   r!   r"   r+   Z
audio_nameÚspeakerZtranscript_pathr   r   r   Ú__init__F   s*   

€zSnips.__init__Únc                 C   sF   | j | }tj || j¡}| d¡j}| j| \}}}|t||||fS )uŠ  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:
                File name
            str:
                Transcription of audio
            str:
                Insideâ€“outsideâ€“beginning (IOB) label of transcription
            str:
                Intention label of the audio.
        Ú )	r3   r-   r.   Úrelpathr*   Úwith_suffixr6   r   Ú_SAMPLE_RATE)r9   r<   r+   r>   Ú	file_nameÚ
transcriptr   r   r   r   r   Úget_metadatae   s
   
zSnips.get_metadatac                 C   s2   |   |¡}t| j|d |d ƒ}|f|dd…  S )u  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:
                File name
            str:
                Transcription of audio
            str:
                Insideâ€“outsideâ€“beginning (IOB) label of transcription
            str:
                Intention label of the audio.
        r   r   N)rC   r   r*   )r9   r<   ÚmetadataÚwaveformr   r   r   Ú__getitem__‚   s   
zSnips.__getitem__c                 C   s
   t | jƒS )N)Úlenr3   )r9   r   r   r   Ú__len__œ   s   
zSnips.__len__)Nr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r8   r   r5   r   r   r   r;   Úintr   rC   ÚtorchÚTensorrF   rH   r   r   r   r   r   8   s&    û
þý
üû
ú "r   )r-   Úpathlibr   Útypingr   r   r   r   rN   Útorch.utils.datar   Útorchaudio.datasets.utilsr   r@   r,   r5   r   r   r   r   r   r   Ú<module>   s    