a
    âñhà  ã                   @   s–   d Z ddlZddlmZmZ ddlZddlmZ ddlm	Z	m
Z
mZmZmZ g d¢Zee dœd	d
„Zee dœdd„Zdd„ Zee dœdd„ZdS )z.Defines utilities for switching audio backendsé    N)ÚOptionalÚList)Úis_module_availableé   )Ú
no_backendÚsox_backendÚsox_io_backendÚsoundfile_backendÚ_soundfile_backend)Úlist_audio_backendsÚget_audio_backendÚset_audio_backend)Úreturnc                  C   s6   g } t dƒr|  d¡ t dƒr2|  d¡ |  d¡ | S )z]List available backends

    Returns:
        List[str]: The list of available backends.
    Ú	soundfileztorchaudio._torchaudioÚsoxÚsox_io)r   Úappend©Úbackends© r   úX/home/yuhw/wc/uboone-dl-vtx/venv/lib/python3.9/site-packages/torchaudio/backend/utils.pyr      s    


r   )Úbackendc                 C   s²   | dur*| t ƒ vr*td| › dt ƒ › d�ƒ‚| du r8t}nZ| dkrPt d¡ t}nB| dkr^t}n4| dkr‚tjr|t d	¡ t	}q’t
}ntd
| › d�ƒ‚dD ]}tt|t||ƒƒ q–dS )a  Set the backend for I/O operation

    Args:
        backend (Optional[str]): Name of the backend.
            One of ``"sox"``, ``"sox_io"`` or ``"soundfile"`` based on availability
            of the system. If ``None`` is provided the  current backend is unassigned.
    Nz	Backend "z$" is not one of available backends: Ú.r   zÿ"sox" backend is being deprecated. The default backend will be changed to "sox_io" backend in 0.8.0 and "sox" backend will be removed in 0.9.0. Please migrate to "sox_io" backend. Please refer to https://github.com/pytorch/audio/issues/903 for the detail.r   r   a`  The interface of "soundfile" backend is planned to change in 0.8.0 to match that of "sox_io" backend and the current interface will be removed in 0.9.0. To use the new interface, do `torchaudio.USE_SOUNDFILE_LEGACY_INTERFACE = False` before setting the backend to "soundfile". Please refer to https://github.com/pytorch/audio/issues/903 for the detail.zUnexpected backend "ú")ÚsaveÚloadZload_wavÚinfo)r   ÚRuntimeErrorr   ÚwarningsÚwarnr   r   Ú
torchaudioZUSE_SOUNDFILE_LEGACY_INTERFACEr	   r
   ÚNotImplementedErrorÚsetattrÚgetattr)r   ÚmoduleÚfuncr   r   r   r   %   s2    ÿÿÿÿr   c                  C   s@   t ƒ } d| v rtdƒ n$d| v r*tdƒ nt d¡ td ƒ d S )Nr   r   zNo audio backend is available.)r   r   r   r   r   r   r   r   Ú_init_audio_backendQ   s    


r&   c                   C   sR   t jtjkrdS t jtjkr dS t jtjkr0dS t jtjtjfv rFdS tdƒ‚dS )z”Get the name of the current backend

    Returns:
        Optional[str]: The name of the current backend or ``None`` if no backend is assigned.
    Nr   r   r   zUnknown backend.)r    r   r   r   r   r	   r
   Ú
ValueErrorr   r   r   r   r   \   s    r   )Ú__doc__r   Útypingr   r   r    Z!torchaudio._internal.module_utilsr   Ú r   r   r   r	   r
   Ú__all__Ústrr   r   r&   r   r   r   r   r   Ú<module>   s   ,