
    h<                        S SK r S SKJr  S SKJrJrJrJrJrJ	r	  S SK
r
S SKrS SKJr  S SKJr  S SKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  \" S5      S\\\\   4   4S j5       rS\4S jr S r!S r"S r#g)    N)	lru_cache)BinaryIODictOptionalTupleTypeUnion)lazy_import_sox_ext)CodecConfig)lazy_import_ffmpeg_ext   )soundfile_backend)Backend)AudioMetaData)FFmpegBackend)SoundfileBackend)
SoXBackendreturnc                      0 n [        5       R                  5       (       a	  [        U S'   [        5       R                  5       (       a	  [        U S'   [
        R                  (       a	  [        U S'   U $ )Nffmpegsox	soundfile)r   is_availabler   r
   r   r   _IS_SOUNDFILE_AVAILABLEr   )backend_specss    Q/var/www/auris/envauris/lib/python3.13/site-packages/torchaudio/_backend/utils.pyget_available_backendsr      sX    .0M,,.."/h))++)e00%5k"    c                     UR                  U 5      =n(       a  U$ [        SU  S3S[        UR                  5       5       S35      e)NzUnsupported backend 'z' specified; zplease select one of z	 instead.)get
ValueErrorlistkeys)backend_namebackendsbackends      r   get_backendr'   !   sL    ,,|,,w,#L>?#D$9#:)D
 	
r   c                  \  ^^ [        5       mS[        [        [        [        R
                  4   S[        [           S[        [           S[        4U4S jjm   S	S[        [        [        [        R
                  4   S[        [           S[        S[        [           S[        4
U4S jjjn U $ )
Nuriformatr$   r   c                    > Ub  [        UT5      $ TR                  5        H  nUR                  X5      (       d  M  Us  $    [        SU  SU S35      eNz0Couldn't find appropriate backend to handle uri z and format .r'   values
can_decodeRuntimeErrorr)   r*   r$   r&   r%   s       r   
dispatcher!get_info_func.<locals>.dispatcher.   `     #|X66(G!!#.. ) McUR^_e^ffghiir   buffer_sizer&   c                 :   > T" XU5      nUR                  XU5      $ )a  Get signal information of an audio file.

Note:
    When the input type is file-like object, this function cannot
    get the correct length (``num_samples``) for certain formats,
    such as ``vorbis``.
    In this case, the value of ``num_samples`` is ``0``.

Args:
    uri (path-like object or file-like object):
        Source of audio data. The following types are accepted:

        * ``path-like``: File path or URL.
        * ``file-like``: Object with ``read(size: int) -> bytes`` method,
          which returns byte string of at most ``size`` length.

    format (str or None, optional):
        If not ``None``, interpreted as hint that may allow backend to override the detected format.
        (Default: ``None``)

    buffer_size (int, optional):
        Size of buffer to use when processing file-like objects, in bytes. (Default: ``4096``)

    backend (str or None, optional):
        I/O backend to use.
        If ``None``, function selects backend given input and available backends.
        Otherwise, must be one of [``"ffmpeg"``, ``"sox"``, ``"soundfile"``],
        with the corresponding backend available.
        (Default: ``None``)

        .. seealso::
           :ref:`backend`

Returns:
    AudioMetaData
)info)r)   r*   r6   r&   r3   s       r   r8   get_info_func.<locals>.info9   s#    T S'2||C55r   )N   N)
r   r	   r   strosPathLiker   r   intr   )r8   r%   r3   s    @@r   get_info_funcr?   +   s    %'H	j8S"++-.	j8@	jU]^aUb	j		j !%!%	+68S"++-.+6+6 +6 #	+6
 
+6 +6Z Kr   c                    ^^ [        5       mS[        [        [        [        R
                  4   S[        [           S[        [           S[        4U4S jjm       SS[        [        [        [        R
                  4   S[        S[        S[        S	[        S[        [           S
[        S[        [           S[        [        R                  [        4   4U4S jjjn U $ )Nr)   r*   r$   r   c                    > Ub  [        UT5      $ TR                  5        H  nUR                  X5      (       d  M  Us  $    [        SU  SU S35      er,   r.   r2   s       r   r3   !get_load_func.<locals>.dispatcherl   r5   r   frame_offset
num_frames	normalizechannels_firstr6   r&   c           	      j   > [         R                  " S5        T" XU5      nUR                  XX#XEU5      $ )a"  Load audio data from source.

.. warning::
    In 2.9, this function's implementation will be changed to use
    :func:`~torchaudio.load_with_torchcodec` under the hood. Some
    parameters like ``normalize``, ``format``, ``buffer_size``, and
    ``backend`` will be ignored. We recommend that you port your code to
    rely directly on TorchCodec's decoder instead:
    https://docs.pytorch.org/torchcodec/stable/generated/torchcodec.decoders.AudioDecoder.html#torchcodec.decoders.AudioDecoder.

By default (``normalize=True``, ``channels_first=True``), this function returns Tensor with
``float32`` dtype, and the shape of `[channel, time]`.

Note:
    The formats this function can handle depend on the availability of backends.
    Please use the following functions to fetch the supported formats.

    - FFmpeg: :py:func:`torchaudio.utils.ffmpeg_utils.get_audio_decoders`
    - Sox: :py:func:`torchaudio.utils.sox_utils.list_read_formats`
    - SoundFile: Refer to `the official document <https://pysoundfile.readthedocs.io/>`__.

.. warning::

    ``normalize`` argument does not perform volume normalization.
    It only converts the sample type to `torch.float32` from the native sample
    type.

    When the input format is WAV with integer type, such as 32-bit signed integer, 16-bit
    signed integer, 24-bit signed integer, and 8-bit unsigned integer, by providing ``normalize=False``,
    this function can return integer Tensor, where the samples are expressed within the whole range
    of the corresponding dtype, that is, ``int32`` tensor for 32-bit signed PCM,
    ``int16`` for 16-bit signed PCM and ``uint8`` for 8-bit unsigned PCM. Since torch does not
    support ``int24`` dtype, 24-bit signed PCM are converted to ``int32`` tensors.

    ``normalize`` argument has no effect on 32-bit floating-point WAV and other formats, such as
    ``flac`` and ``mp3``.

    For these formats, this function always returns ``float32`` Tensor with values.


Args:
    uri (path-like object or file-like object):
        Source of audio data.
    frame_offset (int, optional):
        Number of frames to skip before start reading data.
    num_frames (int, optional):
        Maximum number of frames to read. ``-1`` reads all the remaining samples,
        starting from ``frame_offset``.
        This function may return the less number of frames if there is not enough
        frames in the given file.
    normalize (bool, optional):
        When ``True``, this function converts the native sample type to ``float32``.
        Default: ``True``.

        If input file is integer WAV, giving ``False`` will change the resulting Tensor type to
        integer type.
        This argument has no effect for formats other than integer WAV type.

    channels_first (bool, optional):
        When True, the returned Tensor has dimension `[channel, time]`.
        Otherwise, the returned Tensor's dimension is `[time, channel]`.

    format (str or None, optional):
        If not ``None``, interpreted as hint that may allow backend to override the detected format.
        (Default: ``None``)

    buffer_size (int, optional):
        Size of buffer to use when processing file-like objects, in bytes. (Default: ``4096``)

    backend (str or None, optional):
        I/O backend to use.
        If ``None``, function selects backend given input and available backends.
        Otherwise, must be one of [``"ffmpeg"``, ``"sox"``, ``"soundfile"``],
        with the corresponding backend being available. (Default: ``None``)

        .. seealso::
           :ref:`backend`

Returns:
    (torch.Tensor, int): Resulting Tensor and sample rate.
        If the input file has integer wav format and normalization is off, then it has
        integer type, else ``float32`` type. If ``channels_first=True``, it has
        `[channel, time]` else `[time, channel]`.
a  In 2.9, this function's implementation will be changed to use torchaudio.load_with_torchcodec` under the hood. Some parameters like ``normalize``, ``format``, ``buffer_size``, and ``backend`` will be ignored. We recommend that you port your code to rely directly on TorchCodec's decoder instead: https://docs.pytorch.org/torchcodec/stable/generated/torchcodec.decoders.AudioDecoder.html#torchcodec.decoders.AudioDecoder.)warningswarnload)	r)   rC   rD   rE   rF   r*   r6   r&   r3   s	           r   rJ   get_load_func.<locals>.loadw   s<    | 	K	
 S'2||Czn^ijjr   )r   TTNr:   N)r   r	   r   r;   r<   r=   r   r   r>   boolr   torchTensor)rJ   r%   r3   s    @@r   get_load_funcrP   i   s
   %'H	j8S"++-.	j8@	jU]^aUb	j		j # $!%gk8S"++-.gkgk gk 	gk
 gk gk gk #gk 
u||S 	!gk gkR Kr   c                    ^^ [        5       mS[        [        [        [        R
                  4   S[        [           S[        [           S[        4U4S jjm       SS[        [        [        [        R
                  4   S[        R                  S[        S[        S[        [           S	[        [           S
[        [           S[        S[        [           S[        [        [        [        [        4      4U4S jjjn U $ )Nr)   r*   r$   r   c                    > Ub  [        UT5      $ TR                  5        H  nUR                  X5      (       d  M  Us  $    [        SU  SU S35      er,   )r'   r/   
can_encoder1   r2   s       r   r3   !get_save_func.<locals>.dispatcher   r5   r   srcsample_raterF   encodingbits_per_sampler6   r&   compressionc
                 l   > [         R                  " S5        T
" XU5      nUR                  XX#XEXgU	5	      $ )aL  Save audio data to file.

.. warning::
    In 2.9, this function's implementation will be changed to use
    :func:`~torchaudio.save_with_torchcodec` under the hood. Some
    parameters like format, encoding, bits_per_sample, buffer_size, and
    ``backend`` will be ignored. We recommend that you port your code to
    rely directly on TorchCodec's decoder instead:
    https://docs.pytorch.org/torchcodec/stable/generated/torchcodec.encoders.AudioEncoder

Note:
    The formats this function can handle depend on the availability of backends.
    Please use the following functions to fetch the supported formats.

    - FFmpeg: :py:func:`torchaudio.utils.ffmpeg_utils.get_audio_encoders`
    - Sox: :py:func:`torchaudio.utils.sox_utils.list_write_formats`
    - SoundFile: Refer to `the official document <https://pysoundfile.readthedocs.io/>`__.

Args:
    uri (str or pathlib.Path): Path to audio file.
    src (torch.Tensor): Audio data to save. must be 2D tensor.
    sample_rate (int): sampling rate
    channels_first (bool, optional): If ``True``, the given tensor is interpreted as `[channel, time]`,
        otherwise `[time, channel]`.
    format (str or None, optional): Override the audio format.
        When ``uri`` argument is path-like object, audio format is
        inferred from file extension. If the file extension is missing or
        different, you can specify the correct format with this argument.

        When ``uri`` argument is file-like object,
        this argument is required.

        Valid values are ``"wav"``, ``"ogg"``, and ``"flac"``.
    encoding (str or None, optional): Changes the encoding for supported formats.
        This argument is effective only for supported formats, i.e.
        ``"wav"`` and ``""flac"```. Valid values are

        - ``"PCM_S"`` (signed integer Linear PCM)
        - ``"PCM_U"`` (unsigned integer Linear PCM)
        - ``"PCM_F"`` (floating point PCM)
        - ``"ULAW"`` (mu-law)
        - ``"ALAW"`` (a-law)

    bits_per_sample (int or None, optional): Changes the bit depth for the
        supported formats.
        When ``format`` is one of ``"wav"`` and ``"flac"``,
        you can change the bit depth.
        Valid values are ``8``, ``16``, ``24``, ``32`` and ``64``.

    buffer_size (int, optional):
        Size of buffer to use when processing file-like objects, in bytes. (Default: ``4096``)

    backend (str or None, optional):
        I/O backend to use.
        If ``None``, function selects backend given input and available backends.
        Otherwise, must be one of [``"ffmpeg"``, ``"sox"``, ``"soundfile"``],
        with the corresponding backend being available.
        (Default: ``None``)

        .. seealso::
           :ref:`backend`

    compression (CodecConfig, float, int, or None, optional):
        Compression configuration to apply.

        If the selected backend is FFmpeg, an instance of :py:class:`CodecConfig` must be provided.

        Otherwise, if the selected backend is SoX, a float or int value corresponding to option ``-C`` of the
        ``sox`` command line interface must be provided. For instance:

        ``"mp3"``
            Either bitrate (in ``kbps``) with quality factor, such as ``128.2``, or
            VBR encoding with quality factor such as ``-4.2``. Default: ``-4.5``.

        ``"flac"``
            Whole number from ``0`` to ``8``. ``8`` is default and highest compression.

        ``"ogg"``, ``"vorbis"``
            Number from ``-1`` to ``10``; ``-1`` is the highest compression
            and lowest quality. Default: ``3``.

        Refer to http://sox.sourceforge.net/soxformat.html for more details.

a  In 2.9, this function's implementation will be changed to use torchaudio.save_with_torchcodec` under the hood. Some parameters like format, encoding, bits_per_sample, buffer_size, and ``backend`` will be ignored. We recommend that you port your code to rely directly on TorchCodec's encoder instead: https://docs.pytorch.org/torchcodec/stable/generated/torchcodec.encoders.AudioEncoder)rH   rI   save)r)   rU   rV   rF   r*   rW   rX   r6   r&   rY   r3   s             r   r[   get_save_func.<locals>.save   sC    @ 	d	
 S'2||k6_cn
 	
r   )TNNNr:   NN)r   r	   r   r;   r<   r=   r   r   rN   rO   r>   rM   r   float)r[   r%   r3   s    @@r   get_save_funcr^      s   %'H	j8S"++-.	j8@	jU]^aUb	j		j  $ $"&)-!%@Dk
8S"++-.k
\\k
 k
 	k

 k
 3-k
 "#k
 k
 #k
 eK$;<=k
 k
Z Kr   )$r<   	functoolsr   typingr   r   r   r   r   r	   rH   rN   torchaudio._extensionr
   torchaudio.ior   torio._extensionr    r   r&   r   commonr   r   r   r   r   r   r   r;   r   r'   r?   rP   r^    r   r   <module>rg      s~    	  ? ?   5 % 3   ! ! '  4S$w-%7 8  
7 
;|wt{r   