o
    ei                     @   s,   d Z ddlZddlmZ G dd deZdS )aO   Specifies the inference interfaces for metric estimation modules.

Authors:
 * Aku Rouhe 2021
 * Peter Plantinga 2021
 * Loren Lugosch 2020
 * Mirco Ravanelli 2020
 * Titouan Parcollet 2021
 * Abdel Heba 2021
 * Andreas Nautsch 2022, 2023
 * Pooneh Mousavi 2023
 * Sylvain de Langen 2023
 * Adel Moumen 2023
 * Pradnya Kandarkar 2023
    N)
Pretrainedc                   @   s8   e Zd ZdZddgZg dZdd Zdd Zd	d
 ZdS )SNREstimatorzA "ready-to-use" SNR estimator.encoderencoder_out)stat_poolingsnrmaxsnrminc           	      C   sr  | ddd}|d|d}t| jdrY| jjdkr3||jdddd  }||jdddd  }n&| jjd	krY||jddd |jddd }||jddd |jddd }t	|j
d |j
d }|j
d |j
d ksrJ d
|dd}tj|ddd|f d|ddd|f dgdd}| j|}| ddd}| j|}| j| }| |}|S )a  Run SI-SNR estimation on the estimated sources, and mixture.

        Arguments
        ---------
        mix : torch.Tensor
            The mixture of sources of shape B X T
        predictions : torch.Tensor
            of size (B x T x C),
            where B is batch size
                  T is number of time points
                  C is number of sources

        Returns
        -------
        tensor
            Estimate of SNR
        r         separation_norm_typemaxT)dimkeepdimstnormzlengths changeN)r   )permutereshapesizehasattrhparamsr   r   meanstdminshaperepeattorchcat	unsqueezemodsr   r   r   squeezegettrue_snrrange)	selfmixpredictionsmin_T
mix_repeatinp_catenc	enc_statssnrhat r*   [/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/speechbrain/inference/metrics.pyestimate_batch   s:   
zSNREstimator.estimate_batchc                 C   s   |  ||S )zJust run the batch estimate)r,   )r!   r"   r#   r*   r*   r+   forwardX   s   zSNREstimator.forwardc                 C   s(   | j j| j j }|| }|| j j }|S )z(Convert from 0-1 range to true snr range)r   r   r   )r!   inpranger*   r*   r+   r    \   s   zSNREstimator.gettrue_snrrangeN)	__name__
__module____qualname____doc__MODULES_NEEDEDHPARAMS_NEEDEDr,   r-   r    r*   r*   r*   r+   r      s    <r   )r3   r    speechbrain.inference.interfacesr   r   r*   r*   r*   r+   <module>   s    