
    hC                     (   S r SSKrSSKJrJr  SSKrSSKJr  SSK	J
r
  Sr\R                  " S5      (       a   SSKr\R                  rS	rO\R"                  " S5      r0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S_S!S"_SSSSSSSS#SSS$.
ErS% rS&S&S&S&S'S(S(SSS)S*.
rS+\S,\4S- jr\SGS.\S+\\   S/\
4S0 jj5       rS1S2S3S4S5S6S7.r\     SHS.\S8\S9\S:\S;\S+\\   S/\\R6                  \4   4S< jj5       rS=\R:                  S>\S?\4S@ jrS>\S?\4SA jrS=\R:                  S+\S>\S?\4SB jr \     SIS.\SC\R6                  SD\S;\SE\\!   S+\\   S>\\   S?\\   4SF jj5       r"g! \ a    \R"                  " S
5      r GN2f = f)JzCThe new soundfile backend which will become default in 0.8.0 onward    N)OptionalTuple)module_utils   )AudioMetaDataF	soundfileTz[requires soundfile, but we failed to import it. Please check the installation of soundfile.zFrequires soundfile, but it is not installed. Please install soundfile.PCM_S8   PCM_16   PCM_24   PCM_32    PCM_U8FLOATDOUBLE@   ULAWALAW	IMA_ADPCMMS_ADPCMGSM610	VOX_ADPCMG721_32G723_24G723_40DWVW_12      )
DWVW_16DWVW_24DWVW_NDPCM_8DPCM_16VORBISALAC_16ALAC_20ALAC_24ALAC_32c                 v    U [         ;  a  [        R                  " SU  S35        [         R                  U S5      $ )NzThe z subtype is unknown to TorchAudio. As a result, the bits_per_sample attribute will be set to 0. If you are seeing this warning, please report by opening an issue on github (after checking for existing/closed ones). You may otherwise ignore this warning.r   )_SUBTYPE_TO_BITS_PER_SAMPLEwarningswarnget)subtypes    ]/var/www/auris/envauris/lib/python3.13/site-packages/torchaudio/_backend/soundfile_backend.py_get_bit_depthr2   E   s=    117) 5 5	
 '**7A66    PCM_SPCM_UPCM_Fr&   )
r	   r   r   r   r   r   r   r   r   r&   formatr0   c                 <    U S:X  a  g[         R                  US5      $ )NFLACUNKNOWN)_SUBTYPE_TO_ENCODINGr/   )r7   r0   s     r1   _get_encodingr<   ^   s     ##GY77r3   filepathreturnc           
          [         R                  " U 5      n[        UR                  UR                  UR
                  [        UR                  5      [        UR                  UR                  5      S9$ )a7  Get signal information of an audio file.

Note:
    ``filepath`` argument is intentionally annotated as ``str`` only, even though it accepts
    ``pathlib.Path`` object as well. This is for the consistency with ``"sox_io"`` backend,
    which has a restriction on type annotation due to TorchScript compiler compatiblity.

Args:
    filepath (path-like object or file-like object):
        Source of audio data.
    format (str or None, optional):
        Not used. PySoundFile does not accept format hint.

Returns:
    AudioMetaData: meta data of the given audio.

)bits_per_sampleencoding)
r   infor   
samplerateframeschannelsr2   r0   r<   r7   )r=   r7   sinfos      r1   rB   rB   d   sT    & NN8$E&u}}5u||U]]; r3   int8uint8int16int32float32float64)r	   r   r   r   r   r   frame_offset
num_frames	normalizechannels_firstc                    [         R                  " U S5       nUR                  S:w  d  U(       a  SnO?UR                  [        ;  a  [        SUR                   35      e[        UR                     nUR                  USU5      nUR                  XSS9n	UR                  n
SSS5        [        R                  " W	5      n	U(       a  U	R                  5       n	U	W
4$ ! , (       d  f       N?= f)a  Load audio data from file.

Note:
    The formats this function can handle depend on the soundfile installation.
    This function is tested on the following formats;

    * WAV

        * 32-bit floating-point
        * 32-bit signed integer
        * 16-bit signed integer
        * 8-bit unsigned integer

    * FLAC
    * OGG/VORBIS
    * SPHERE

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

.. 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.

Note:
    ``filepath`` argument is intentionally annotated as ``str`` only, even though it accepts
    ``pathlib.Path`` object as well. This is for the consistency with ``"sox_io"`` backend,
    which has a restriction on type annotation due to TorchScript compiler compatiblity.

Args:
    filepath (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):
        Not used. PySoundFile does not accept format hint.

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]`.
rWAVrK   zUnsupported subtype: NT)	always_2d)r   	SoundFiler7   r0   _SUBTYPE2DTYPE
ValueError_prepare_readreadrC   torch
from_numpyt)r=   rM   rN   rO   rP   r7   file_dtyperD   waveformsample_rates              r1   loadra      s    d 
		Xs	+u<<5 IE]].04U]]ODEE"5==1E$$\4D::ft:<&& 
, )H::<[   
,	+s   B	C
C(r^   rA   r@   c           
      Z   U(       d  U(       dx  [         R                  S[         R                  S[         R                  S[         R                  S[         R
                  S0R                  U 5      nU(       d  [        SU  35      eU$ US:X  a  gSU 3$ US	:X  a  U(       d  gUS:X  a  [        S
5      eSU 3$ US:X  a  US;   a  g[        S5      eUS:X  a  US;   a  gUS:X  a  g[        S5      eUS:X  a  US;   a  g[        S5      eUS:X  a  US;   a  g[        S5      e[        SU S35      e)Nr   r   r   r   r   zUnsupported dtype for wav: r
   PCM_r4   z/wav does not support 8-bit signed PCM encoding.r5   Nr
   z.wav only supports 8-bit unsigned PCM encoding.r6   )Nr   r   z/wav only supports 32/64-bit float PCM encoding.r   z(wav only supports 8-bit mu-law encoding.r   z'wav only supports 8-bit a-law encoding.zwav does not support .)rZ   rH   rI   rJ   rK   rL   r/   rW   )r^   rA   r@   r0   s       r1   _get_subtype_for_wavrf      sL   XXXwx c%j   #>ug!FGGNao&''7aNOOo&''7i'IJJ7j(b JKK6i'CDD6i'BCC
,XJa8
99r3   c                     U S;   a  U(       a  SU 3$ S$ U S;   a  [        SU  S35      eU S:X  a  US;   a  g[        S	5      eU S
:X  a  g
[        SU  S35      e)N)Nr4   rc   r   )r5   r6   zsph does not support z
 encoding.r   rd   z,sph only supports 8-bit for mu-law encoding.r   re   )rW   )rA   r@   s     r1   _get_subtype_for_sphererh     s|    ?"+:o&'HH%%0
*EFF6i'GHH6
,XJa8
99r3   c                 j   US:X  a  [        XU5      $ US:X  a8  U(       a  [        S5      eU(       d  gUS:  a  [        S5      eUS:X  a  S$ S	U 3$ US
;   a1  U(       a  [        S5      eUb  US:X  a  gUS:X  a  g[        SU 35      eUS:X  a  gUS:X  a  [        X#5      $ US;   a  g[        SU 35      e)Nwavflaczflac does not support encoding.r   r   z+flac does not support bits_per_sample > 24.r
   r	   rc   )oggvorbisz,ogg/vorbis does not support bits_per_sample.rm   r&   opusOPUSzUnexpected encoding: mp3MPEG_LAYER_IIIsph)nisnistzUnsupported format: )rf   rW   rh   )r^   r7   rA   r@   s       r1   _get_subtyperu   (  s    #E_EE>??RJKK*a/xMtO;L5MM""KLLx83v0
;<<&xAA 
+F84
55r3   srcr`   compressionc                 6   UR                   S:w  a  [        SUR                    S35      eUb  [        R                  " S5        [	        U S5      (       a  Uc  [        S5      eUR                  5       nO+[        U 5      R                  S5      S	   R                  5       nUS
;  a  [        S5      eUS:X  a  [        R                  " S5        [        UR                  XU5      n	US;   a  Uc  SnU(       a  UR                  5       n[        R                  " XX)US9  g)a  Save audio data to file.

Note:
    The formats this function can handle depend on the soundfile installation.
    This function is tested on the following formats;

    * WAV

        * 32-bit floating-point
        * 32-bit signed integer
        * 16-bit signed integer
        * 8-bit unsigned integer

    * FLAC
    * OGG/VORBIS
    * SPHERE

Note:
    ``filepath`` argument is intentionally annotated as ``str`` only, even though it accepts
    ``pathlib.Path`` object as well. This is for the consistency with ``"sox_io"`` backend,
    which has a restriction on type annotation due to TorchScript compiler compatiblity.

Args:
    filepath (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]`.
    compression (float of None, optional): Not used.
        It is here only for interface compatibility reson with "sox_io" backend.
    format (str or None, optional): Override the audio format.
        When ``filepath`` 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 ``filepath`` argument is file-like object,
        this argument is required.

        Valid values are ``"wav"``, ``"ogg"``, ``"vorbis"``,
        ``"flac"`` and ``"sph"``.
    encoding (str or None, optional): Changes the encoding for supported formats.
        This argument is effective only for supported formats, sush as
        ``"wav"``, ``""flac"`` and ``"sph"``. 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"``, ``"flac"`` or ``"sph"``,
        you can change the bit depth.
        Valid values are ``8``, ``16``, ``24``, ``32`` and ``64``.

Supported formats/encodings/bit depth/compression are:

``"wav"``
    - 32-bit floating-point PCM
    - 32-bit signed integer PCM
    - 24-bit signed integer PCM
    - 16-bit signed integer PCM
    - 8-bit unsigned integer PCM
    - 8-bit mu-law
    - 8-bit a-law

    Note:
        Default encoding/bit depth is determined by the dtype of
        the input Tensor.

``"flac"``
    - 8-bit
    - 16-bit (default)
    - 24-bit

``"ogg"``, ``"vorbis"``
    - Doesn't accept changing configuration.

``"sph"``
    - 8-bit signed integer PCM
    - 16-bit signed integer PCM
    - 24-bit signed integer PCM
    - 32-bit signed integer PCM (default)
    - 8-bit mu-law
    - 8-bit a-law
    - 16-bit a-law
    - 24-bit a-law
    - 32-bit a-law

   zExpected 2D Tensor, got zD.Nzr`save` function of "soundfile" backend does not support "compression" parameter. The argument is silently ignored.writez0`format` is required when saving to file object.re   )Nr
   r   r   r   r   zInvalid bits_per_sample.r   zvSaving audio with 24 bits per sample might warp samples near -1. Using 16 bits per sample might be able to avoid this.)rs   rt   rr   NIST)filedatarC   r0   r7   )ndimrW   r-   r.   hasattrRuntimeErrorlowerstrsplitru   r^   r\   r   rz   )
r=   rv   r`   rP   rw   r7   rA   r@   extr0   s
             r1   saver   D  s   L xx1}3CHH:R@AA0	
 x!!>QRRlln(m!!#&r*00277344"D	
 399c_EG $$eegOO]cdr3   )N)r   r{   TTN)TNNNN)#__doc__r-   typingr   r   rZ   torchaudio._internalr   
_mod_utilscommonr   _IS_SOUNDFILE_AVAILABLEis_module_availabler   no_op_requires_soundfile	Exceptionfail_with_messager,   r2   r;   r   r<   rB   rV   intboolTensorra   r^   rf   rh   ru   floatr    r3   r1   <module>r      sy   I  "  ; !    !!+..
(.."& %66Pab b b	
 a R b A A   a  q q  q!" r#$ 7 >7  8# 8 8 3    :    `!`!`! `! 	`!
 `! SM`! 5<<`! `!F(: (:s (:S (:V:c :C :6 6S 6C 6RU 68 
  #' "%)DeDe	De De 	De
 %De SMDe smDe c]De Dec	  
(::i

s   E5 5FF