o
    æS™i
  ã                   @   sr   d dl mZmZ d dlmZmZ d dlZd dlm	Z	m
Z
 d dlmZmZ eG dd„ dƒƒZe
G dd	„ d	e	ƒƒZdS )
é    )ÚasdictÚ	dataclass)ÚAnyÚDictN)ÚTorchaudioFeatureExtractorÚregister_extractor)ÚEPSILONÚSecondsc                   @   sº   e Zd ZU dZeed< dZeed< dZe	ed< dZ
e	ed< d	Zeed
< d	Zeed< eZeed< dZeed< dZeed< d	Zeed< deeef fdd„Zedeeef dd fdd„ƒZdS )ÚTorchaudioSpectrogramConfigg        ÚditherÚpoveyÚwindow_typegš™™™™™™?Úframe_lengthg{®Gáz„?Úframe_shiftTÚremove_dc_offsetÚround_to_power_of_twoÚenergy_floorÚmin_durationg
×£p=
ï?Úpreemphasis_coefficientÚ
raw_energyÚreturnc                 C   s   t | ƒS ©N)r   )Úself© r   úO/home/ubuntu/.local/lib/python3.10/site-packages/lhotse/features/spectrogram.pyÚto_dict   s   z#TorchaudioSpectrogramConfig.to_dictÚdatac                 C   s   t di | ¤ŽS )Nr   )r
   )r   r   r   r   Ú	from_dict   s   z%TorchaudioSpectrogramConfig.from_dictN)Ú__name__Ú
__module__Ú__qualname__r   ÚfloatÚ__annotations__r   Ústrr   r	   r   r   Úboolr   r   r   r   r   r   r   r   r   Ústaticmethodr   r   r   r   r   r
   
   s   
  r
   c                	   @   sn   e Zd ZdZdZeZdd„ Zdedefdd„Z	e
d	ejd
ejdedejfdd„ƒZe
dejdefdd„ƒZdS )ÚTorchaudioSpectrogramz`Log spectrogram feature extractor based on ``torchaudio.compliance.kaldi.spectrogram`` function.Úspectrogramc                 O   s   ddl m} ||i |¤ŽS )Nr   )r'   )Útorchaudio.compliance.kaldir'   )r   ÚargsÚkwargsr'   r   r   r   Ú_feature_fn)   s   z!TorchaudioSpectrogram._feature_fnÚsampling_rater   c                 C   s8   ddl m} t| jj| ƒ}| jjr||ƒd d S |S )Nr   )Ú_next_power_of_2é   é   )r(   r-   ÚintÚconfigr   r   )r   r,   r-   Úwindow_sizer   r   r   Úfeature_dim.   s   ÿÿýz!TorchaudioSpectrogram.feature_dimÚ
features_aÚ
features_bÚenergy_scaling_factor_bc              
   C   s&   t  t  tt  | ¡|t  |¡  ¡¡S r   )ÚnpÚlogÚmaximumr   Úexp)r4   r5   r6   r   r   r   Úmix8   s   ýÿzTorchaudioSpectrogram.mixÚfeaturesc                 C   s   t t t | ¡¡ƒS r   )r!   r7   Úsumr:   )r<   r   r   r   Úcompute_energyE   s   z$TorchaudioSpectrogram.compute_energyN)r   r   r    Ú__doc__Únamer
   Úconfig_typer+   r0   r3   r%   r7   Úndarrayr!   r;   r>   r   r   r   r   r&   "   s$    
ÿÿÿþr&   )Údataclassesr   r   Útypingr   r   Únumpyr7   Úlhotse.features.baser   r   Úlhotse.utilsr   r	   r
   r&   r   r   r   r   Ú<module>   s    