ó
    óó�j�
  ã                   ó0   • S r SSKrSSKJr   " S S5      rg)zPreprocessors for audioé    N)ÚResamplec                   ó.   • \ rS rSrSrSS jrS rS rSrg)	ÚAudioNormalizeré   a  Normalizes audio into a standard format

Arguments
---------
sample_rate : int
    The sampling rate to which the incoming signals should be converted.
mix : {"avg-to-mono", "keep"}
    "avg-to-mono" - add all channels together and normalize by number of
    channels. This also removes the channel dimension, resulting in [time]
    format tensor.
    "keep" - don't normalize channel information

Example
-------
>>> from speechbrain.dataio import audio_io
>>> example_file = (
...     "tests/samples/multi-mic/speech_-0.82918_0.55279_-0.082918.flac"
... )
>>> signal, sr = audio_io.load(example_file, channels_first=False)
>>> normalizer = AudioNormalizer(sample_rate=8000)
>>> normalized = normalizer(signal, sr)
>>> signal.shape
torch.Size([160000, 4])
>>> normalized.shape
torch.Size([80000])

NOTE
----
This will also upsample audio. However, upsampling cannot produce meaningful
information in the bandwidth which it adds. Generally models will not work
well for upsampled data if they have not specifically been trained to do so.
c                 óR   • Xl         US;  a  [        SU 35      eX l        0 U l        g )N)úavg-to-monoÚkeepz Unexpected mixing configuration )Úsample_rateÚ
ValueErrorÚmixÚ_cached_resamplers)Úselfr
   r   s      Ú«C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\speechbrain/dataio/preprocess.pyÚ__init__ÚAudioNormalizer.__init__*   s1   € Ø&ÔØÐ-Ó-ÜÐ?À¸uÐEÓFÐFØŒØ"$ˆÕó    c                 óð   • X R                   ;  a"  [        X R                  5      U R                   U'   U R                   U   nU" UR                  S5      5      R	                  S5      nU R                  U5      $ )a  Perform normalization

Arguments
---------
audio : torch.Tensor
    The input waveform torch tensor. Assuming [time, channels],
    or [time].
sample_rate : int
    Rate the audio was sampled at.

Returns
-------
audio : torch.Tensor
    Channel- and sample-rate-normalized audio.
r   )r   r   r
   Ú	unsqueezeÚsqueezeÚ_mix)r   Úaudior
   Ú	resamplerÚ	resampleds        r   Ú__call__ÚAudioNormalizer.__call__1   sm   € ð  ×5Ñ5Ó5ä3;Ø×-Ñ-ó4ˆD×#Ñ# KÑ0ð ×+Ñ+¨KÑ8ˆ	Ù˜eŸo™o¨aÓ0Ó1×9Ñ9¸!Ó<ˆ	Ø�y‰y˜Ó#Ð#r   c                 ó®   • UR                  5       S:H  nU R                  S:X  a   U(       a  U$ [        R                  " US5      $ U R                  S:X  a  U$ g)zHandle channel mixingé   r   r	   N)Údimr   ÚtorchÚmean)r   r   Ú
flat_inputs      r   r   ÚAudioNormalizer._mixJ   sM   € à—Y‘Y“[ AÑ%ˆ
Ø�8‰8�}Ó$ÞØ�Ü—:’:˜e QÓ'Ð'Ø�8‰8�vÓØˆLð r   )r   r   r
   N)i€>  r   )	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   Ú__static_attributes__© r   r   r   r      s   † ñôB%ò$õ2r   r   )r'   r   Úspeechbrain.augment.time_domainr   r   r)   r   r   Ú<module>r+      s   ðÙ ã å 4÷Jò Jr   