o
    i                     @   s   d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
Z
ddlmZ ed1i ddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.ZG d/d0 d0eZdS )2zTransformation module.    N)OrderedDict)Sequence)	signature)dynamic_importidentityz-espnet.transform.transform_interface:Identity	time_warpz&espnet.transform.spec_augment:TimeWarp	time_maskz&espnet.transform.spec_augment:TimeMask	freq_maskz&espnet.transform.spec_augment:FreqMaskspec_augmentz)espnet.transform.spec_augment:SpecAugmentspeed_perturbationz*espnet.transform.perturb:SpeedPerturbationvolume_perturbationz+espnet.transform.perturb:VolumePerturbationnoise_injectionz'espnet.transform.perturb:NoiseInjectionbandpass_perturbationz-espnet.transform.perturb:BandpassPerturbationrir_convolvez$espnet.transform.perturb:RIRConvolvedeltaz%espnet.transform.add_deltas:AddDeltascmvnzespnet.transform.cmvn:CMVNutterance_cmvnz#espnet.transform.cmvn:UtteranceCMVNfbankz.espnet.transform.spectrogram:LogMelSpectrogramspectrogramz(espnet.transform.spectrogram:Spectrogramstftz!espnet.transform.spectrogram:Stftistftz"espnet.transform.spectrogram:IStft
stft2fbankz3espnet.transform.spectrogram:Stft2LogMelSpectrogramwpezespnet.transform.wpe:WPEchannel_selectorz1espnet.transform.channel_selector:ChannelSelectorc                   @   s,   e Zd ZdZd	ddZdd Zd	ddZdS )
Transformationa  Apply some functions to the mini-batch

    Examples:
        >>> kwargs = {"process": [{"type": "fbank",
        ...                        "n_mels": 80,
        ...                        "fs": 16000},
        ...                       {"type": "cmvn",
        ...                        "stats": "data/train/cmvn.ark",
        ...                        "norm_vars": True},
        ...                       {"type": "delta", "window": 2, "order": 2}]}
        >>> transform = Transformation(kwargs)
        >>> bs = 10
        >>> xs = [np.random.randn(100, 80).astype(np.float32)
        ...       for _ in range(bs)]
        >>> xs = transform(xs)
    Nc           	      C   sZ  |d ur;t |trt|| _n1tj|dd}t|| _t | jts+J t	| jW d    n1 s5w   Y  ndg d| _t
 | _| jdddkrt| jd D ]K\}}t |tsdJ t	|t|}|d}t|t}z|d
i || j|< W qU ty   zt|}W n	 ty   Y  w td|j|  w d S td	| jd )Nzutf-8)encoding
sequential)modeprocessr   r   typezExpected signature: {}({})Not supporting mode={} )
isinstancedictcopydeepcopyconfioopenyaml	safe_loadr   r   	functionsget	enumeratepopr   import_alias	TypeErrorr   
ValueErrorloggingerrorformat__name__NotImplementedError)	selfconffilefidxr   optsprocess_type	class_objsignar!   r!   S/home/ubuntu/.local/lib/python3.10/site-packages/espnet/transform/transformation.py__init__9   sH   


zTransformation.__init__c                 C   s.   dd dd | j D  }d| jj|S )N
c                 s   s     | ]\}}d  ||V  qdS )z
    {}: {}N)r4   .0kvr!   r!   r?   	<genexpr>a   s    
z*Transformation.__repr__.<locals>.<genexpr>z{}({}))joinr+   itemsr4   	__class__r5   )r7   repr!   r!   r?   __repr__`   s   
zTransformation.__repr__c              
      s:  t |tsd}|g}nd}t trfddtt|D | jdddkrtt| jd D ]X}| j| ztj	W n t
yJ   i Y nw fdd	| D  z"d
urmdv rm fddt|D }n
 fdd|D }W q1 ty   td|  w n
td| jd |r|S |d S )zReturn new mini-batch

        :param Union[Sequence[np.ndarray], np.ndarray] xs:
        :param Union[Sequence[str], str] uttid_list:
        :return: batch:
        :rtype: List[np.ndarray]
        FTc                    s   g | ]} qS r!   r!   )rC   _)
uttid_listr!   r?   
<listcomp>u   s    z+Transformation.__call__.<locals>.<listcomp>r   r   r   c                    s   i | ]\}}| v r||qS r!   r!   rB   )paramr!   r?   
<dictcomp>   s    z+Transformation.__call__.<locals>.<dictcomp>Nuttidc                    s"   g | ]\}}||fi  qS r!   r!   )rC   xu_kwargsfuncr!   r?   rN      s   " c                    s   g | ]
}|fi  qS r!   r!   )rC   rR   rT   r!   r?   rN      s    z$Catch a exception from {}th func: {}r    r   )r"   r   strrangelenr&   r,   r+   r   
parametersr1   rH   zip	Exceptionr2   fatalr4   r6   )r7   xsrM   kwargsis_batchr:   r!   )rU   rV   rO   rM   r?   __call__f   sB   



zTransformation.__call__)N)r5   
__module____qualname____doc__r@   rK   ra   r!   r!   r!   r?   r   '   s
    
'r   r!   )rd   r$   r'   r2   collectionsr   collections.abcr   inspectr   r)   espnet.utils.dynamic_importr   r#   r/   objectr   r!   r!   r!   r?   <module>   sf    	
