U
    %d                     @   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 ddd	g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)ListOptional)module_utils   )
no_backendsoundfile_backendsox_io_backendlist_audio_backendsget_audio_backendset_audio_backend)returnc                  C   s.   g } t dr| d t  r*| d | S )z]List available backends

    Returns:
        List[str]: The list of available backends.
    	soundfilesox_io)
_mod_utilsZis_module_availableappendZis_sox_availablebackends r   </tmp/pip-unpacked-wheel-lbdmvq91/torchaudio/backend/utils.pyr	      s    


)backendc                 C   s   | dk	r*| t  kr*td|  dt   d| dkr8t}n,| dkrFt}n| dkrTt}ntd|  dd	D ]}tt|t|| qhdS )
a  Set the backend for I/O operation

    Args:
        backend (str or None): Name of the backend.
            One of ``"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   r   zUnexpected backend "")saveloadinfo)	r	   RuntimeErrorr   r   r   NotImplementedErrorsetattr
torchaudiogetattr)r   modulefuncr   r   r   r      s    c                  C   s@   t  } d| krtd n$d| kr*td ntd td  d S )Nr   r   zNo audio backend is available.)r	   r   warningswarnr   r   r   r   _init_audio_backend7   s    


r$   c                   C   s<   t jtjkrdS t jtjkr dS t jtjkr0dS tddS )zGet the name of the current backend

    Returns:
        Optional[str]: The name of the current backend or ``None`` if no backend is assigned.
    Nr   r   zUnknown backend.)r   r   r   r   r   
ValueErrorr   r   r   r   r
   B   s    )__doc__r"   typingr   r   r   Ztorchaudio._internalr   r    r   r   r   __all__strr	   r   r$   r
   r   r   r   r   <module>   s   