
    h9                         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	rS
rSrSrSSS.rS rS\S\S\\\\\\4   4S jr " S S\
5      rg)    N)Path)OptionalTupleUnion)Tensor)Dataset)download_url_to_file)_extract_tar_load_waveformSpeechCommandsspeech_commands_v0.02_nohash__background_noise_i>  @743935421bb51cccdb6bdd152e04c5c70274e935c82119ad7faeec31780d811d@af14739ee7dc311471de98f5f9d2c9191b18aedfe957f4a6ff791c709868ff58)z@http://download.tensorflow.org/data/speech_commands_v0.01.tar.gzz@http://download.tensorflow.org/data/speech_commands_v0.02.tar.gzc                 j   / nU H  n[         R                  R                  X5      n[        U5       nX% Vs/ s HM  n[         R                  R	                  [         R                  R                  XR                  5       5      5      PMO     sn-  nS S S 5        M     U$ s  snf ! , (       d  f       M  = fN)ospathjoinopennormpathstrip)root	filenamesoutputfilenamefilepathfileobjlines          Z/var/www/auris/envauris/lib/python3.13/site-packages/torchaudio/datasets/speechcommands.py
_load_listr"      s    F77<</(^wV]^V]drww''T::<(HIV]^^F ^  M _ ^s   B#AB
B#B##
B2	r   r   returnc                    [         R                  R                  X5      n[         R                  R                  U5      u  p4[         R                  R                  U5      u  pV[         R                  R	                  U5      u  pu[         R                  R	                  U5      u  puUR                  [
        5      u  p[        U	5      n	U[        XhU	4$ r   )r   r   relpathsplitsplitextHASH_DIVIDERintSAMPLE_RATE)
r   r   r%   reldirr   _labelspeaker
speaker_idutterance_numbers
             r!   _get_speechcommands_metadatar1      s    ggooh-Gww}}W-Fww}}V$HA !!(+JG!!'*JG#*==#> J+,K4DDD    c                       \ rS rSrSr\\SS4S\\\	4   S\S\S\
S	\\   S
S4S jjrS\S
\\\\\\4   4S jrS\S
\\\\\\4   4S jrS
\4S jrSrg)SPEECHCOMMANDS2   a  *Speech Commands* :cite:`speechcommandsv2` 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 ``"speech_commands_v0.01"`` and ``"speech_commands_v0.02"``
        (default: ``"speech_commands_v0.02"``)
    folder_in_archive (str, optional):
        The top-level directory of the dataset. (default: ``"SpeechCommands"``)
    download (bool, optional):
        Whether to download the dataset if it is not found at root path. (default: ``False``).
    subset (str or None, optional):
        Select a subset of the dataset [None, "training", "validation", "testing"]. None means
        the whole dataset. "validation" and "testing" are defined in "validation_list.txt" and
        "testing_list.txt", respectively, and "training" is the rest. Details for the files
        "validation_list.txt" and "testing_list.txt" are explained in the README of the dataset
        and in the introduction of Section 7 of the original paper and its reference 12. The
        original paper can be found `here <https://arxiv.org/pdf/1804.03209.pdf>`_. (Default: ``None``)
FNr   urlfolder_in_archivedownloadsubsetr#   c                    Ub  US;  a  [        S5      eUS;   a&  SnSn[        R                  R                  XbU-   5      n[        R                  " U5      n[        R                  R                  X5      U l        [        R                  R                  U5      n[        R                  R                  X5      n	UR                  SS5      S   n[        R                  R                  X85      n[        R                  R                  X5      U l        U(       a  [        R                  R                  U R                  5      (       dY  [        R                  R                  U	5      (       d   [        R                  US 5      n
[        X)U
S	9  [        XR                  5        OG[        R                  R                  U R                  5      (       d  [!        S
U R                   S35      eUS:X  a  [#        U R                  S5      U l        g US:X  a  [#        U R                  S5      U l        g US:X  a  ['        [#        U R                  SS5      5      n[)        S [+        U R                  5      R-                  S5       5       5      nU Vs/ s HB  n[.        U;   d  M  [0        U;  d  M  [        R                  R3                  U5      U;  d  M@  UPMD     snU l        g [)        S [+        U R                  5      R-                  S5       5       5      nU Vs/ s H  n[.        U;   d  M  [0        U;  d  M  UPM     snU l        g s  snf s  snf )N)training
validationtestingzSWhen `subset` is not None, it must be one of ['training', 'validation', 'testing'].)zspeech_commands_v0.01r   z$http://download.tensorflow.org/data/z.tar.gz.   r   )hash_prefixz	The path zT doesn't exist. Please check the ``root`` path or set `download=True` to download itr<   zvalidation_list.txtr=   ztesting_list.txtr;   c              3   8   #    U  H  n[        U5      v   M     g 7fr   str.0ps     r!   	<genexpr>*SPEECHCOMMANDS.__init__.<locals>.<genexpr>|        M,LqCFF,L   z*/*.wavc              3   8   #    U  H  n[        U5      v   M     g 7fr   rB   rD   s     r!   rG   rH      rI   rJ   )
ValueErrorr   r   r   fspath_archivebasenamersplit_pathisdirisfile
_CHECKSUMSgetr	   r
   existsRuntimeErrorr"   _walkersetsortedr   globr(   EXCEPT_FOLDERr   )selfr   r6   r7   r8   r9   base_urlext_archiverO   archivechecksumexcludeswalkerws                 r!   __init__SPEECHCOMMANDS.__init__H   s    &0U"Urss 
 
 >H#K'',,x{):;C yyT=77##C('',,t.??3*1-GGLL):EWW\\$:
77==,,ww~~g..)~~c48H(8LWjj177>>$**--"

| ,[ [ 
 \!%djj2GHDLy %djj2DEDLz!:djj2GI[\]HMD,<,A,A),LMMF  A1$ )6a)? DFGGDTDTUVDW_gDg DL MD,<,A,A),LMMF'-^v!1BA}\]G]Av^DL _s*   	M M '!M M M%M1Mnc                 J    U R                   U   n[        X R                  5      $ )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 the audio
    int:
        Sample rate
    str:
        Label
    str:
        Speaker ID
    int:
        Utterance number
)rX   r1   rN   )r]   rg   fileids      r!   get_metadataSPEECHCOMMANDS.get_metadata   s     * a+FMMBBr2   c                 p    U R                  U5      n[        U R                  US   US   5      nU4US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:
        Label
    str:
        Speaker ID
    int:
        Utterance number
r      N)rj   r   rN   )r]   rg   metadatawaveforms       r!   __getitem__SPEECHCOMMANDS.__getitem__   sA    ( $$Q'!$--!hqkJ{Xab\))r2   c                 ,    [        U R                  5      $ r   )lenrX   )r]   s    r!   __len__SPEECHCOMMANDS.__len__   s    4<<  r2   )rN   rQ   rX   )__name__
__module____qualname____firstlineno____doc__URLFOLDER_IN_ARCHIVEr   rC   r   boolr   re   r)   r   rj   r   rp   rt   __static_attributes__ r2   r!   r4   r4   2   s    0 !2 $<_CI<_ <_ 	<_
 <_ <_ 
<_|Cc CeCc3,C&D C0*S *U63S#+E%F *0! !r2   r4   )r   pathlibr   typingr   r   r   torchr   torch.utils.datar   torchaudio._internalr	   torchaudio.datasets.utilsr
   r   r|   r{   r(   r\   r*   rT   r"   rC   r)   r1   r4   r   r2   r!   <module>r      s    	  ) )  $ 5 B$ $ IK IK
E3 Ec EeCcSVX[D[>\ E(E!W E!r2   