o
    ðpiO  ã                   @  sš   U d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	 d dl
mZ d dlmZ ddlmZ erAed	 Zd
ed< ed Zd
ed< g ZG dd„ deƒZdS )é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚLiteralÚ
NamedTuple)Ú	TypeAlias)Ú	DATA_HOME)Údownloadé   )ÚAudioClassificationDataset)ÚtrainÚdevr   Ú_ModeLiteral)ÚrawZmelspectrogramZmfccZlogmelspectrogramZspectrogramÚ_FeatTypeLiteralc                      s¢   e Zd ZU dZdddœZded< g d¢Zded	< ej 	d
dd¡Z
ded< ej 	d
d¡Zded< G dd„ deƒZ				d)d*‡ fd!d"„Zd+d$d%„Zd,d'd(„Z‡  ZS )-ÚESC50a’  
    The ESC-50 dataset is a labeled collection of 2000 environmental audio recordings
    suitable for benchmarking methods of environmental sound classification. The dataset
    consists of 5-second-long recordings organized into 50 semantical classes (with
    40 examples per class)

    Reference:
        ESC: Dataset for Environmental Sound Classification
        http://dx.doi.org/10.1145/2733373.2806390

    Args:
       mode (str, optional): It identifies the dataset mode (train or dev). Default:train.
       split (int, optional): It specify the fold of dev dataset. Default:1.
       feat_type (str, optional): It identifies the feature type that user wants to extract of an audio file. Default:raw.
       archive(dict, optional): it tells where to download the audio archive. Default:None.

    Returns:
        :ref:`api_paddle_io_Dataset`. An instance of ESC50 dataset.

    Examples:

        .. code-block:: python

            >>> # doctest: +TIMEOUT(60)
            >>> import paddle

            >>> mode = 'dev'
            >>> esc50_dataset = paddle.audio.datasets.ESC50(mode=mode,  # type: ignore[arg-type]
            ...                                         feat_type='raw')
            >>> for idx in range(5):
            ...     audio, label = esc50_dataset[idx]
            ...     # do something with audio, label
            ...     print(audio.shape, label)
            ...     # [audio_data_length] , label_id
            [220500] 0
            [220500] 14
            [220500] 36
            [220500] 36
            [220500] 19

            >>> esc50_dataset = paddle.audio.datasets.ESC50(mode=mode,  # type: ignore[arg-type]
            ...                                         feat_type='mfcc',
            ...                                         n_mfcc=40)
            >>> for idx in range(5):
            ...     audio, label = esc50_dataset[idx]
            ...     # do something with mfcc feature, label
            ...     print(audio.shape, label)
            ...     # [feature_dim, length] , label_id
            [40, 1723] 0
            [40, 1723] 14
            [40, 1723] 36
            [40, 1723] 36
            [40, 1723] 19

    z<https://paddleaudio.bj.bcebos.com/datasets/ESC-50-master.zipZ 7771e4b9d86d0945acce719c7a59305a)ÚurlÚmd5zdict[str, str]Úarchive)2ZDogZRoosterÚPigZCowZFrogZCatZHenzInsects (flying)ZSheepZCrowZRainz	Sea waveszCrackling fireZCricketszChirping birdszWater dropsZWindzPouring waterzToilet flushZThunderstormzCrying babyZSneezingZClappingZ	BreathingZCoughingZ	FootstepsZLaughingzBrushing teethZSnoringzDrinking, sippingz
Door knockzMouse clickzKeyboard typingzDoor, wood creakszCan openingzWashing machinezVacuum cleanerzClock alarmz
Clock tickzGlass breakingZ
HelicopterZChainsawZSirenzCar hornZEngineZTrainzChurch bellsZAirplaneZ	FireworkszHand sawz	list[str]Ú
label_listzESC-50-masterÚmetaz	esc50.csvÚstrZaudioÚ
audio_pathc                   @  sF   e Zd ZU ded< ded< ded< ded< ded< ded< ded< d	S )
zESC50.meta_infor   ÚfilenameÚfoldÚtargetÚcategoryZesc10Zsrc_fileZtakeN)Ú__name__Ú
__module__Ú__qualname__Ú__annotations__© r"   r"   úb/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/paddle/audio/datasets/esc50.pyÚ	meta_info¥   s   
 r$   r   r
   r   NÚmoder   ÚsplitÚintÚ	feat_typer   údict[str, str] | NoneÚkwargsr   ÚreturnÚNonec                   sX   |t ddƒv sJ d|› ƒ‚|d ur|| _|  ||¡\}}tƒ jd|||dœ|¤Ž d S )Nr
   é   zCThe selected split should be integer, and 1 <= split <= 5, but got )ÚfilesÚlabelsr(   r"   )Úranger   Ú	_get_dataÚsuperÚ__init__)Úselfr%   r&   r(   r   r*   r.   r/   ©Ú	__class__r"   r#   r3   ®   s   ÿÿ
ÿzESC50.__init__úlist[meta_info]c                 C  sp   g }t tj t| j¡dƒ!}| ¡ dd … D ]}| | j| 	¡  
d¡Ž ¡ qW d   ƒ |S 1 s1w   Y  |S )NÚrr
   ú,)ÚopenÚosÚpathÚjoinr   r   Ú	readlinesÚappendr$   Ústripr&   )r4   ÚretÚrfÚliner"   r"   r#   Ú_get_meta_infoÀ   s   ÿ
ÿýzESC50._get_meta_infoútuple[list[str], list[int]]c                 C  sö   t j t j t| j¡¡rt j t j t| j¡¡s'tj	| j
d t| j
d dd |  ¡ }g }g }|D ]E}|\}}}	}
}
}
}
|dkrYt|ƒ|krY| t j t| j|¡¡ | t|	ƒ¡ |dkrvt|ƒ|krv| t j t| j|¡¡ | t|	ƒ¡ q1||fS )Nr   r   T)Ú
decompressr   )r;   r<   Úisdirr=   r   r   Úisfiler   r	   Zget_path_from_urlr   rD   r'   r?   )r4   r%   r&   r$   r.   r/   Úsampler   r   r   Ú_r"   r"   r#   r1   Ç   s0   ÿþü€zESC50._get_data)r   r
   r   N)r%   r   r&   r'   r(   r   r   r)   r*   r   r+   r,   )r+   r7   )r%   r   r&   r'   r+   rE   )r   r   r    Ú__doc__r   r!   r   r;   r<   r=   r   r   r   r$   r3   rD   r1   Ú__classcell__r"   r"   r5   r#   r   +   s    
 9þ9û
r   )Ú
__future__r   r;   Útypingr   r   r   r   Ztyping_extensionsr   Zpaddle.dataset.commonr   Zpaddle.utilsr	   Zdatasetr   r   r!   r   Ú__all__r   r"   r"   r"   r#   Ú<module>   s    ÿÿ	