o
    ei~                     @   sZ   d Z ddlZddlmZ ddlZddlmZ eeZdee	 fddZ
dd	 Zd
d ZdS )zjLibrary for checking the torchaudio backend.

Authors
-------
 * Mirco Ravanelli 2021
 * Adel Moumen 2025
    N)Optional)
get_loggerreturnc                  C   sb   t tdsdS tjd} t| dkrdS zt| d }t| d }W ||fS  ty0   Y dS w )z{Tries parsing the torchaudio major version.

    Returns
    -------
    The parsed major version, otherwise ``None``.
    __version__N.   r      )hasattr
torchaudior   splitlenint	Exception)version_splitmajor_versionminor_version r   c/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/speechbrain/utils/torch_audio_backend.py"try_parse_torchaudio_major_version   s   
r   c                  C   s   t  \} }| du rtd dS | dkr+|dkr+t }t|dkr)td dS dS td t }|dkrDtd	 td
 dS dS )zWChecks the torchaudio backend and sets it to soundfile if
    windows is detected.
    Nz|Failed to detect torchaudio major version; unsure how to check your setup. We recommend that you keep torchaudio up-to-date.r   r   r   zSpeechBrain could not find any working torchaudio backend. Audio files may fail to load. Follow this link for instructions and troubleshooting: https://speechbrain.readthedocs.io/en/latest/audioloading.htmlzThis version of torchaudio is old. SpeechBrain no longer tries using the torchaudio global backend mechanism in recipes, so if you encounter issues, update torchaudio to >=2.1.0.WindowsztSwitched audio backend to "soundfile" because you are running Windows and you are running an old torchaudio version.	soundfile)	r   loggerwarningr
   list_audio_backendsr   platformsystemset_audio_backend)torchaudio_majortorchaudio_minoravailable_backendscurrent_systemr   r   r   check_torchaudio_backend.   s,   
r!   c                 C   s*   g d}| |vrt d| dt dS )a,  
    Validates the specified audio backend.

    Parameters
    ----------
    backend : str or None
        The name of the backend to validate. Must be one of [None, 'ffmpeg', 'sox', 'soundfile'].

    Raises
    ------
    ValueError
        If the `backend` is not one of the allowed values.
    )Nffmpegsoxr   zbackend must be one of z#Available backends on your system: N)
ValueErrorr
   r   )backendallowed_backendsr   r   r   validate_backendK   s   r'   )__doc__r   typingr   r
   speechbrain.utils.loggerr   __name__r   r   r   r!   r'   r   r   r   r   <module>   s    