o
    siT                     @   s,   d dl Z ddlmZ eddefddZdS )	    N   )script_if_tracing(   th_dbc                 C   sN   dt |  }t| jdd ddg }t j||dddd }||| kS )	a  Compute energy-based VAD from a magnitude spectrogram (or equivalent).

    Args:
        mag_spec (torch.Tensor): the spectrogram to perform VAD on.
            Expected shape (batch, *, freq, time).
            The VAD mask will be computed independently for all the leading
            dimensions until the last two. Independent of the ordering of the
            last two dimensions.
        th_db (int): The threshold in dB from which a TF-bin is considered
            silent.

    Returns:
        :class:`torch.BoolTensor`, the VAD mask.


    Examples
        >>> import torch
        >>> mag_spec = torch.abs(torch.randn(10, 2, 65, 16))
        >>> batch_src_mask = ebased_vad(mag_spec)
       N   T)keepdimr   )torchlog10listshapemaxview)mag_specr   log_magto_viewmax_log_mag r   D/home/ubuntu/.local/lib/python3.10/site-packages/asteroid/dsp/vad.py
ebased_vad   s   r   )r   )r   utils.torch_utilsr   intr   r   r   r   r   <module>   s    