
    ͑i$+                    X   S SK Jr  S SKrS SKJrJrJr  S SKrS SKJr  S SK	J
r
  S SKJr  \(       a
  \" S\\5      rSSS jjrSSS	 jjr     S           SS
 jjrSSS jjr      S                 SS jjr   S         SS jjr  S         SS jjrg)    )annotationsN)TYPE_CHECKINGLiteralTypeVar)Tensor)Variable)Value_TensorOrFloatc                P   U(       a^  [        U [        [        [        45      (       a  S[        R
                  " SU S-  -   5      -  $ S[        R
                  " SU S-  -   5      -  $ SnSnX-
  U-  nSnXR-
  U-  n[        R                  " S5      S-  n[        U [        [        [        45      (       aM  U[        R                  " X-  S	-   5      U-  -   nX:  R                  U R                  5      n	X-  US
U	-
  -  -   nU$ X:  a!  U[        R                  " X-  S	-   5      U-  -   nU$ )a  Convert Hz to Mels.

Args:
    freq (Union[Tensor, float]): The input tensor with arbitrary shape.
    htk (bool, optional): Use htk scaling. Defaults to False.

Returns:
    Union[Tensor, float]: Frequency in mels.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> val = 3.0
        >>> htk_flag = True
        >>> mel_paddle_tensor = paddle.audio.functional.hz_to_mel(
        ...     paddle.to_tensor(val), htk_flag)
     F@      ?     @        竪P@     @@皙@      ;@绽|=   )

isinstancer   r   r	   paddlelog10mathlogastypedtype)
freqhtkf_minf_spmels
min_log_hzmin_log_mellogsteptargetmasks
             b/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/audio/functional/functional.py	hz_to_melr(      s1   * dVXu566FLLte|);<<<DJJsTE\'9::: EDLD D J%-Khhsmd"G$5122&**T%6%>?'II 	 !))$**5}tH 
 
 K $*;e*C!Dw!NNDK    c                   U(       a  SSU S-  -  S-
  -  $ SnSnX#U -  -   nSnXR-
  U-  n[         R                  " S5      S	-  n[        U [        [        [
        45      (       aJ  U[        R                  " XpU-
  -  5      -  nX:  R                  U R                  5      n	X-  US
U	-
  -  -   nU$ X:  a  U[         R                  " XpU-
  -  5      -  nU$ )a  Convert mel bin numbers to frequencies.

Args:
    mel (Union[float, Tensor]): The mel frequency represented as a tensor with arbitrary shape.
    htk (bool, optional): Use htk scaling. Defaults to False.

Returns:
    Union[float, Tensor]: Frequencies in Hz.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> val = 3.0
        >>> htk_flag = True
        >>> mel_paddle_tensor = paddle.audio.functional.mel_to_hz(
        ...     paddle.to_tensor(val), htk_flag)
        ...
r         $@r   r   r   r   r   r   r   r   )
r   r   r   r   r   r	   r   expr   r   )
melr   r   r    freqsr"   r#   r$   r%   r&   s
             r'   	mel_to_hzr/   S   s    * v.455ED3JEJ%-Khhsmd"G#%011fjj+4E)FGG!))#))4H!
 
 L ';5F*G!HHELr)   c                f    [        XS9n[        X#S9n[        R                  " XVXS9n[        XsS9nU$ )a  Compute mel frequencies.

Args:
    n_mels (int, optional): Number of mel bins. Defaults to 64.
    f_min (float, optional): Minimum frequency in Hz. Defaults to 0.0.
    fmax (float, optional): Maximum frequency in Hz. Defaults to 11025.0.
    htk (bool, optional): Use htk scaling. Defaults to False.
    dtype (str, optional): The data type of the return frequencies. Defaults to 'float32'.

Returns:
    Tensor: Tensor of n_mels frequencies in Hz with shape `(n_mels,)`.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> n_mels = 64
        >>> f_min = 0.5
        >>> f_max = 10000
        >>> htk_flag = True

        >>> paddle_mel_freq = paddle.audio.functional.mel_frequencies(
        ...     n_mels, f_min, f_max, htk_flag, 'float64')
)r   r   )r(   r   linspacer/   )	n_melsr   f_maxr   r   min_melmax_melr!   r.   s	            r'   mel_frequenciesr7   ~   s8    B 'G'G??7VADd$ELr)   c           	     f    [         R                  " S[        U 5      S-  [        SUS-  -   5      US9$ )a  Compute fourier frequencies.

Args:
    sr (int): Sample rate.
    n_fft (int): Number of fft bins.
    dtype (str, optional): The data type of the return frequencies. Defaults to 'float32'.

Returns:
    Tensor: FFT frequencies in Hz with shape `(n_fft//2 + 1,)`.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> sr = 16000
        >>> n_fft = 128
        >>> fft_freq = paddle.audio.functional.fft_frequencies(sr, n_fft)
r      r   r1   )r   r2   floatintsrn_fftr   s      r'   fft_frequenciesr?      s.    ( ??1eBi!mSUaZ-@NNr)   c                   Uc  [        U 5      S-  n[        R                  " U[        SUS-  -   5      4US9n[	        XUS9n	[        US-   X4XWS9n
U
SS U
SS -
  nU
R                  S5      U	R                  S5      -
  n[        U5       H]  nX   * X   -  nXS-      XS-      -  n[        R                  " [        R                  " U5      [        R                  " X5      5      X'   M_     US	:X  a'  S
U
SUS-    U
SU -
  -  nUUR                  S5      -  nU$ [        U[        [         45      (       a(  [        R                  R                  R                  XSS9nU$ )a(  Compute fbank matrix.

Args:
    sr (int): Sample rate.
    n_fft (int): Number of fft bins.
    n_mels (int, optional): Number of mel bins. Defaults to 64.
    f_min (float, optional): Minimum frequency in Hz. Defaults to 0.0.
    f_max (Optional[float], optional): Maximum frequency in Hz. Defaults to None.
    htk (bool, optional): Use htk scaling. Defaults to False.
    norm (Union[str, float], optional): Type of normalization. Defaults to 'slaney'.
    dtype (str, optional): The data type of the return matrix. Defaults to 'float32'.

Returns:
    Tensor: Mel transform matrix with shape `(n_mels, n_fft//2 + 1)`.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> sr = 23
        >>> n_fft = 51
        >>> fbank = paddle.audio.functional.compute_fbank_matrix(sr, n_fft)
Nr9   r   r1   r<   )r   r4   r   r   r   slaney       @)paxis)r:   r   zerosr;   r?   r7   	unsqueezerangemaximum
zeros_likeminimumr   nn
functional	normalize)r=   r>   r3   r   r4   r   normr   weightsfftfreqsmel_ffdifframpsilowerupperenorms                    r'   compute_fbank_matrixrY      sr   F }b	A llFCEQJ$78FG "?H 
%#E !"Icr
"EOOA!3!3A!66E 6]	EH$!euU|+ ^^e$fnnU&B

  xuQ!,uWf~=>5??1%% N 
D3,	'	'))&&00r0JNr)   c                   US::  a  [        S5      eUS::  a  [        S5      e[        R                  " U 5      nS[        R                  " [        R                  " XB-  U 5      5      -  nUS[
        R                  " [        X5      5      -  -  nUb;  US:  a  [        S5      e[        R                  " XTUR                  5       U-
  -  5      nU$ )a0  Convert a power spectrogram (amplitude squared) to decibel (dB) units. The function computes the scaling `10 * log10(x / ref)` in a numerically stable way.

Args:
    spect (Tensor): STFT power spectrogram.
    ref_value (float, optional): The reference value. If smaller than 1.0, the db level of the signal will be pulled up accordingly. Otherwise, the db level is pushed down. Defaults to 1.0.
    amin (float, optional): Minimum threshold. Defaults to 1e-10.
    top_db (Optional[float], optional): Threshold the output at `top_db` below the peak. Defaults to None.

Returns:
    Tensor: Power spectrogram in db scale.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> val = 3.0
        >>> decibel_paddle = paddle.audio.functional.power_to_db(
        ...     paddle.to_tensor(val))
r   zamin must be strictly positivez#ref_value must be strictly positiver+   ztop_db must be non-negative)	Exceptionr   	ones_liker   rI   r   max)spect	ref_valueamintop_dboneslog_specs         r'   power_to_dbrd     s    4 qy899A~=>>E"Dfll6>>$+u#EFFHtzz#i"6777HA:9::>>(HLLNV4K,LMOr)   c                   [         R                  " XS9n[         R                  " XS9R                  S5      n[         R                  " [        R
                  [        U5      -  US-   -  U-  5      nUc  US-  nUR                  $ US:X  d   eUS==   S[        R                  " S5      -  -  ss'   U[        R                  " S[        U5      -  5      -  nUR                  $ )aC  Create a discrete cosine transform(DCT) matrix.

Args:
    n_mfcc (int): Number of mel frequency cepstral coefficients.
    n_mels (int): Number of mel filterbanks.
    norm (Optional[str], optional): Normalization type. Defaults to 'ortho'.
    dtype (str, optional): The data type of the return matrix. Defaults to 'float32'.

Returns:
    Tensor: The DCT matrix with shape `(n_mels, n_mfcc)`.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> n_mfcc = 23
        >>> n_mels = 257
        >>> dct = paddle.audio.functional.create_dct(n_mfcc, n_mels)
r1   r   g      ?rC   orthor   r   )	r   arangerG   cosr   pir:   sqrtT)n_mfccr3   rO   r   nkdcts          r'   
create_dctrp   2  s    2 	f*Af*44Q7A
**%-1s7+a/C |s

 55L wA#		#&&tyyuV},--55Lr)   )F)r   r
   r   boolreturnr
   )r-   r
   r   rq   rr   r
   )@   r   g    @Ffloat32)r3   r;   r   r:   r4   r:   r   rq   r   strrr   r   )rt   )r=   r;   r>   r;   r   ru   rr   r   )rs   r   NFrB   rt   )r=   r;   r>   r;   r3   r;   r   r:   r4   float | Noner   rq   rO   zLiteral['slaney'] | floatr   ru   rr   r   )r   r   g      T@)
r^   r   r_   r:   r`   r:   ra   rv   rr   r   )rf   rt   )
rl   r;   r3   r;   rO   zLiteral['ortho'] | Noner   ru   rr   r   )
__future__r   r   typingr   r   r   r   r   paddle.base.frameworkr   
paddle.pirr	   r:   r
   r(   r/   r7   r?   rY   rd   rp    r)   r'   <module>r|      s   #  2 2   * -vu=N3l(X %%% % 
	%
 % %PO4 &.FFF F 	F
 F 
F $F F FV 	))) ) 	)
 )^ %,	$$$ "$ 	$
 $r)   