o
    ik                     @   sT   d Z ddlmZmZmZ ddlmZ ddlmZm	Z	 ddl
mZ G dd deZdS )	zSpecAugment module.    )OptionalSequenceUnion)
AbsSpecAug)MaskAlongAxisMaskAlongAxisVariableMaxWidth)TimeWarpc                       s   e Zd ZdZ										dded	ed
ededeeee f dedede	eeee f  de	ee
ee
 f  def fddZdddZ  ZS )SpecAuga:  Implementation of SpecAug.

    Reference:
        Daniel S. Park et al.
        "SpecAugment: A Simple Data
         Augmentation Method for Automatic Speech Recognition"

    .. warning::
        When using cuda mode, time_warp doesn't have reproducibility
        due to `torch.nn.functional.interpolate`.

    T   bicubicr         Napply_time_warptime_warp_windowtime_warp_modeapply_freq_maskfreq_mask_width_rangenum_freq_maskapply_time_masktime_mask_width_rangetime_mask_width_ratio_rangenum_time_maskc                    s   |s
|s
|s
t d|r|d ur|	d urt dt   || _|| _|| _|r0t||d| _nd | _|r>td||d| _	nd | _	|rc|d urQtd||
d| _
d S |	d ur_td|	|
d| _
d S t dd | _
d S )	NzBEither one of time_warp, time_mask, or freq_mask should be appliedzREither one of "time_mask_width_range" or "time_mask_width_ratio_range" can be used)windowmodefreq)dimmask_width_rangenum_masktime)r   mask_width_ratio_ranger   zVEither one of "time_mask_width_range" or "time_mask_width_ratio_range" should be used.)
ValueErrorsuper__init__r   r   r   r   	time_warpr   	freq_mask	time_maskr   )selfr   r   r   r   r   r   r   r   r   r   	__class__ O/home/ubuntu/.local/lib/python3.10/site-packages/espnet2/asr/specaug/specaug.pyr#      sT   


zSpecAug.__init__c                 C   sV   | j d ur|  ||\}}| jd ur| ||\}}| jd ur'| ||\}}||fS N)r$   r%   r&   )r'   x	x_lengthsr*   r*   r+   forwardY   s   


zSpecAug.forward)
Tr
   r   Tr   r   TNNr   r,   )__name__
__module____qualname____doc__boolintstrr   r   r   floatr#   r/   __classcell__r*   r*   r(   r+   r	   	   sD    	
Br	   N)r3   typingr   r   r   espnet2.asr.specaug.abs_specaugr   espnet2.layers.mask_along_axisr   r   espnet2.layers.time_warpr   r	   r*   r*   r*   r+   <module>   s    