o
    9wiS                     @   sf   d dl mZ d dlZd dlmZmZmZ d dlmZ d dl	m
Z
mZ e
ddjZded	efd
dZdS )    )partialN)
FileFinderProtocolget_annotated)SpeakerVerificationProtocol)Audioget_torchaudio_infodownmix)monoprotocolreturnc              	   C   s  zt |  }W n ttfy   d| j d}t|w d|vrcd|v r5d|vr4d| j d}t|n.t }z||}W n ttfyR   d| j d}t|w || j	d< d| j d}t
| d|vrd	|vrt }d
|v rud
n|d }tt|d| j	d	< d| j d}t
| d|vrd|vrt| j	d< t| j	d< d| j d}t
| d|v }d|v }t| trd}	nd}	z
t t| |	 }W n ttfy   d}
Y nw d}
|
||d}| |fS )a  Check that protocol is suitable for training a model

        - does it provide a training set?
        - does it provide a validation set?
        - does it provide a way to access audio content?
        - does it provide a way to delimit annotated content?

    Returns
    -------
    fixed_protocol : Protocol
    checks: dict
        has_validation : bool
        has_scope : bool
        has_classes : bool

    Raises
    ------
    ValueError if protocol does not pass the check list and cannot be fixed.

    z	Protocol z  does not define a training set.audiowaveformsample_ratezG provides audio with "waveform" key but is missing a "sample_rate" key.zu does not provide the path to audio files. See pyannote.database documentation on how to add an 'audio' preprocessor.z does not provide the path to audio files: adding an 'audio' preprocessor for you. See pyannote.database documentation on how to do that yourself.ztorchaudio.info	soundfiler   )backendz does not precompute the output of torchaudio.info(): adding a 'torchaudio.info' preprocessor for you to speed up dataloaders. See pyannote.database documentation on how to do that yourself.	annotateddurationz does not provide the 'annotated' regions: adding an 'annotated' preprocessor for you. See pyannote.database documentation on how to do that yourself.scopeclassesdevelopment_trialdevelopmentFT)has_validation	has_scopehas_classes)nexttrainAttributeErrorNotImplementedErrorname
ValueErrorr   KeyErrorFileNotFoundErrorpreprocessorsprint
torchaudiolist_audio_backendsr   r   get_durationr   
isinstancer   getattr)r   filemsgfile_finder_backendsr   r   r   validation_methodr   checks r1   Z/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/pyannote/audio/utils/protocol.pycheck_protocol"   sr   



r3   )	functoolsr   r%   pyannote.databaser   r   r   pyannote.database.protocolr   pyannote.audio.core.ior   r   r'   r3   r1   r1   r1   r2   <module>   s   