
    h-              	       "   S SK r S SKJr  S SKJrJrJr  S SKJr  S SK	J
r
  S SKJr  S SKJrJr  SrS	/ S
Q/ SQS.SSSS.S.rSrSrS\4S jrS\S\S\S\\   4S jrS\S\4S jrS\S\4S jr " S S\
5      r " S  S!\5      r " S" S#\5      rg)$    N)Path)ListTupleUnion)Tensor)Dataset)download_url_to_file)_extract_zip_load_waveformi>  zvox1_dev_wav.zip)zIhttps://thor.robots.ox.ac.uk/~vgg/data/voxceleb/vox1a/vox1_dev_wav_partaazIhttps://thor.robots.ox.ac.uk/~vgg/data/voxceleb/vox1a/vox1_dev_wav_partabzIhttps://thor.robots.ox.ac.uk/~vgg/data/voxceleb/vox1a/vox1_dev_wav_partaczIhttps://thor.robots.ox.ac.uk/~vgg/data/voxceleb/vox1a/vox1_dev_wav_partad)@21ec6ca843659ebc2fdbe04b530baa4f191ad4b0971912672d92c158f32226a0@311d21e0c8cbf33573a4fce6c80e5a279d80736274b381c394319fc557159a04@92b64465f2b2a3dc0e4196ae8dd6828cbe9ddd1f089419a11e4cbfe2e1750df0@00e6190c770b27f27d2a3dd26ee15596b17066b715ac111906861a7d09a211a5)archive_nameurls	checksumszvox1_test_wav.zipzGhttps://thor.robots.ox.ac.uk/~vgg/data/voxceleb/vox1a/vox1_test_wav.zip@8de57f347fe22b2c24526e9f444f689ecf5096fc2a92018cf420ff6b5b15eaea)r   urlchecksumdevtestzBhttps://www.robots.ox.ac.uk/~vgg/data/voxceleb/meta/iden_split.txtzAhttps://www.robots.ox.ac.uk/~vgg/data/voxceleb/meta/veri_test.txtrootc           	         S GH  n[         U   S   n[        R                  R                  X5      nUS:X  a  [         U   S   n[         U   S   n[	        US5       n[        XE5       H  u  px[        R                  R                  U [        R                  R                  U5      5      n	[        XyUS9  [	        U	S5       n
UR                  U
R                  5       5        S S S 5        M     S S S 5        O"[         U   S	   n[         U   S
   n[        XsUS9  [        U5        GM"     g ! , (       d  f       M  = f! , (       d  f       N1= f)Nr   r   r   r   r   wb)hash_prefixrbr   r   )_ARCHIVE_CONFIGSospathjoinopenzipbasenamer	   writereadr
   )r   archiver   archive_pathr   r   fr   r   	file_pathf_splits              U/var/www/auris/envauris/lib/python3.13/site-packages/torchaudio/datasets/voxceleb1.py_download_extract_wavsr-   &   s   "'0@ww||D7 e#G,V4D(1+>IlD)Q%(%9MC "T2773C3CC3H II(XNi.'/ /. &: *) #7+E2C'0<H I\"% # /.	 *)s%   A$D:  D(	 D:(
D72D::
E	r*   subsetreturnc                 
   / nUS:X  a  SnOUS:X  a  SnOSn[        US5       nU H7  nUR                  5       u  px[        U5      U:X  d  M&  UR                  U5        M9     S S S 5        [	        U5      $ ! , (       d  f       N= f)Ntrain   r         r)r"   splitintappendsorted)	r   r*   r.   f_listindexr)   lineidr    s	            r,   
_get_flistr>   <   sz    F	5	i	Dzz|HB2w%d#  

 &> 
	s   %A4A44
Bveri_test_pathc                     / n[        US5       nU H)  nUR                  5       u  pVnUR                  XVU45        M+     S S S 5        U$ ! , (       d  f       U$ = f)Nr5   )r"   r6   r8   )r   r?   r:   r)   r<   labelpath1path2s           r,   _get_paired_flistrD   L   sZ    F	nc	"aD"&**,E%MM5/0  
# M	 
#	" Ms   0A		
A
_ext_audioc                 ~    U R                  S5      SS  u  p#nUR                  US5      nSR                  X#U/5      nU$ )N/ -)r6   replacer!   )r*   rE   
speaker_id
youtube_idutterance_idfile_ids         r,   _get_file_idrP   U   sF    +4??3+?+D(JL''
B7Lhh
=>GN    c                   j    \ rS rSrSrSrSS\\\4   S\	SS4S jjr
S	\4S
 jrS	\4S jrS\4S jrSrg)	VoxCeleb1\   a  *VoxCeleb1* :cite:`nagrani2017voxceleb` dataset.

Args:
    root (str or Path): Path to the directory where the dataset is found or downloaded.
    download (bool, optional):
        Whether to download the dataset if it is not found at root path. (Default: ``False``).
z.wavr   downloadr/   Nc                 .   [         R                  " U5      n[         R                  R                  US5      U l        [         R                  R                  U R                  5      (       d,  U(       d  [        SU R                   S35      e[        U5        g g )NwavzDataset not found at z5. Please set `download=True` to download the dataset.)r   fspathr    r!   _pathisdirRuntimeErrorr-   )selfr   rU   s      r,   __init__VoxCeleb1.__init__g   sl    yyWW\\$.
ww}}TZZ(("+DJJ<7lm  #4( )rQ   nc                     [         eNNotImplementedErrorr\   r_   s     r,   get_metadataVoxCeleb1.get_metadatar       !!rQ   c                     [         era   rb   rd   s     r,   __getitem__VoxCeleb1.__getitem__u   rg   rQ   c                     [         era   rb   r\   s    r,   __len__VoxCeleb1.__len__x   rg   rQ   )rY   )F)__name__
__module____qualname____firstlineno____doc__rE   r   strr   boolr]   r7   re   ri   rm   __static_attributes__ rQ   r,   rS   rS   \   sU     J	)U39- 	) 	)$ 	)"c ""S "" "rQ   rS   c                      ^  \ rS rSrSrS\S4S\\\4   S\S\S\	S	S
4
U 4S jjjr
S\S	\\\\\4   4S jrS\S	\\\\\4   4S jrS	\4S jrSrU =r$ )VoxCeleb1Identification|   u  *VoxCeleb1* :cite:`nagrani2017voxceleb` dataset for speaker identification task.

Each data sample contains the waveform, sample rate, speaker id, and the file id.

Args:
    root (str or Path): Path to the directory where the dataset is found or downloaded.
    subset (str, optional): Subset of the dataset to use. Options: ["train", "dev", "test"]. (Default: ``"train"``)
    meta_url (str, optional): The url of meta file that contains the list of subset labels and file paths.
        The format of each row is ``subset file_path". For example: ``1 id10006/nLEBBc9oIFs/00003.wav``.
        ``1``, ``2``, ``3`` mean ``train``, ``dev``, and ``test`` subest, respectively.
        (Default: ``"https://www.robots.ox.ac.uk/~vgg/data/voxceleb/meta/iden_split.txt"``)
    download (bool, optional):
        Whether to download the dataset if it is not found at root path. (Default: ``False``).

Note:
    The file structure of `VoxCeleb1Identification` dataset is as follows:

    └─ root/

     └─ wav/

     └─ speaker_id folders

    Users who pre-downloaded the ``"vox1_dev_wav.zip"`` and ``"vox1_test_wav.zip"`` files need to move
    the extracted files into the same ``root`` directory.
r1   Fr   r.   meta_urlrU   r/   Nc                 T  > [         TU ]  X5        US;  a  [        S5      e[        R                  R                  U[        R                  R                  U5      5      n[        R                  R                  U5      (       d  [        X55        [        U R                  XR5      U l        g )N)r1   r   r   z0`subset` must be one of ['train', 'dev', 'test'])superr]   
ValueErrorr   r    r!   r$   existsr	   r>   rY   _flist)r\   r   r.   r{   rU   meta_list_path	__class__s         r,   r]    VoxCeleb1Identification.__init__   sw     	(11OPPdBGG,<,<X,FGww~~n-- : ^DrQ   r_   c                     U R                   U   n[        X R                  5      nUR                  S5      S   n[	        USS 5      nU[
        XC4$ )ad  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

Returns:
    Tuple of the following items;

    str:
        Path to audio
    int:
        Sample rate
    int:
        Speaker ID
    str:
        File ID
rJ   r   r4   N)r   rP   rE   r6   r7   SAMPLE_RATE)r\   r_   r*   rO   rL   s        r,   re   $VoxCeleb1Identification.get_metadata   sO    & KKN	y//:]]3'*
AB(
+z::rQ   c                 p    U R                  U5      n[        U R                  US   US   5      nU4USS -   $ )zLoad 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
    int:
        Speaker ID
    str:
        File ID
r   r2   Nre   r   rY   )r\   r_   metadatawaveforms       r,   ri   #VoxCeleb1Identification.__getitem__   sA    $ $$Q'!$**hqk8A;G{Xab\))rQ   c                 ,    [        U R                  5      $ ra   lenr   rl   s    r,   rm   VoxCeleb1Identification.__len__       4;;rQ   r   )ro   rp   rq   rr   rs   _IDEN_SPLIT_URLr   rt   r   ru   r]   r7   r   re   r   ri   rm   rv   __classcell__r   s   @r,   ry   ry   |   s    8 5<_ot
E#t)$
E.1
EGJ
Ehl
E	
E 
E;c ;eCc3,>&? ;2*S *U63S+@%A *,     rQ   ry   c            
          ^  \ rS rSrSr\S4S\\\4   S\S\	SS4U 4S	 jjjr
S
\S\\\\\\\4   4S jrS
\S\\\\\\\4   4S jrS\4S jrSrU =r$ )VoxCeleb1Verification   u  *VoxCeleb1* :cite:`nagrani2017voxceleb` dataset for speaker verification task.

Each data sample contains a pair of waveforms, sample rate, the label indicating if they are
from the same speaker, and the file ids.

Args:
    root (str or Path): Path to the directory where the dataset is found or downloaded.
    meta_url (str, optional): The url of meta file that contains a list of utterance pairs
        and the corresponding labels. The format of each row is ``label file_path1 file_path2".
        For example: ``1 id10270/x6uYqmx31kE/00001.wav id10270/8jEAjG6SegY/00008.wav``.
        ``1`` means the two utterances are from the same speaker, ``0`` means not.
        (Default: ``"https://www.robots.ox.ac.uk/~vgg/data/voxceleb/meta/veri_test.txt"``)
    download (bool, optional):
        Whether to download the dataset if it is not found at root path. (Default: ``False``).

Note:
    The file structure of `VoxCeleb1Verification` dataset is as follows:

    └─ root/

     └─ wav/

     └─ speaker_id folders

    Users who pre-downloaded the ``"vox1_dev_wav.zip"`` and ``"vox1_test_wav.zip"`` files need to move
    the extracted files into the same ``root`` directory.
Fr   r{   rU   r/   Nc                 2  > [         TU ]  X5        [        R                  R	                  U[        R                  R                  U5      5      n[        R                  R                  U5      (       d  [        X$5        [        U R                  U5      U l
        g ra   )r}   r]   r   r    r!   r$   r   r	   rD   rY   r   )r\   r   r{   rU   r   r   s        r,   r]   VoxCeleb1Verification.__init__   s`    (dBGG,<,<X,FGww~~n-- :'

NCrQ   r_   c                     U R                   U   u  p#n[        U5      n[        X0R                  5      n[        X@R                  5      nX4[        X%U4$ )a  Get metadata for the n-th sample from the dataset. Returns filepaths instead of waveforms,
but otherwise returns the same fields as :py:func:`__getitem__`.

Args:
    n (int): The index of the sample

Returns:
    Tuple of the following items;

    str:
        Path to audio file of speaker 1
    str:
        Path to audio file of speaker 2
    int:
        Sample rate
    int:
        Label
    str:
        File ID of speaker 1
    str:
        File ID of speaker 2
)r   r7   rP   rE   r   )r\   r_   rA   file_path_spk1file_path_spk2file_id_spk1file_id_spk2s          r,   re   "VoxCeleb1Verification.get_metadata   sK    . 15A-~E
#NOOD#NOOD{EQ]]]rQ   c                     U R                  U5      n[        U R                  US   US   5      n[        U R                  US   US   5      nX44USS -   $ )ab  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 of speaker 1
    Tensor:
        Waveform of speaker 2
    int:
        Sample rate
    int:
        Label
    str:
        File ID of speaker 1
    str:
        File ID of speaker 2
r   r3   r2   Nr   )r\   r_   r   waveform_spk1waveform_spk2s        r,   ri   !VoxCeleb1Verification.__getitem__  s\    , $$Q'&tzz8A;L&tzz8A;L-<<rQ   c                 ,    [        U R                  5      $ ra   r   rl   s    r,   rm   VoxCeleb1Verification.__len__4  r   rQ   r   )ro   rp   rq   rr   rs   _VERI_TEST_URLr   rt   r   ru   r]   r7   r   re   r   ri   rm   rv   r   r   s   @r,   r   r      s    8 @N`e DU39- D DY] Djn D D^c ^eCc3S,H&I ^:=S =U663S#+M%N =6     rQ   r   )r   pathlibr   typingr   r   r   torchr   torch.utils.datar   torchaudio._internalr	   torchaudio.datasets.utilsr
   r   r   r   r   r   rt   r-   r>   rD   rP   rS   ry   r   rw   rQ   r,   <module>r      s    	  % %  $ 5 B  +

  ,XV! , WT# #,S S # $s)  C  C S " "@X i X v^ I ^ rQ   