o
    8wi@,                     @   s    d dl mZ G dd deZdS )   )SpeakerDiarizationProtocolc                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd S )!SpeakerSpottingProtocola  Speaker spotting protocol

    Parameters
    ----------
    preprocessors : dict or (key, preprocessor) iterable
        When provided, each protocol item (dictionary) are preprocessed, such
        that item[key] = preprocessor(item). In case 'preprocessor' is not
        callable, it should be a string containing placeholder for item keys
        (e.g. {'audio': '/path/to/{uri}.wav'})
    c                 C      t d)Nz=Custom speaker spotting protocol should implement "trn_iter".NotImplementedErrorself r	   h/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/pyannote/database/protocol/speaker_spotting.pytrn_iter-      z SpeakerSpottingProtocol.trn_iterc                 C      d S Nr	   r   r	   r	   r
   trn_enrol_iter2      z&SpeakerSpottingProtocol.trn_enrol_iterc                 C   r   r   r	   r   r	   r	   r
   trn_try_iter5   r   z$SpeakerSpottingProtocol.trn_try_iterc                 C   r   )Nz=Custom speaker spotting protocol should implement "dev_iter".r   r   r	   r	   r
   dev_iter8   r   z SpeakerSpottingProtocol.dev_iterc                 C   r   )NzCCustom speaker spotting protocol should implement "dev_enrol_iter".r   r   r	   r	   r
   dev_enrol_iter=   r   z&SpeakerSpottingProtocol.dev_enrol_iterc                 C   r   )NzACustom speaker spotting protocol should implement "dev_try_iter".r   r   r	   r	   r
   dev_try_iterB   r   z$SpeakerSpottingProtocol.dev_try_iterc                 C   r   )Nz=Custom speaker spotting protocol should implement "tst_iter".r   r   r	   r	   r
   tst_iterG   r   z SpeakerSpottingProtocol.tst_iterc                 C   r   )NzCCustom speaker spotting protocol should implement "tst_enrol_iter".r   r   r	   r	   r
   tst_enrol_iterL   r   z&SpeakerSpottingProtocol.tst_enrol_iterc                 C   r   )NzACustom speaker spotting protocol should implement "tst_try_iter".r   r   r	   r	   r
   tst_try_iterQ   r   z$SpeakerSpottingProtocol.tst_try_iterc                 c   $    |   }|D ]}| |V  qdS )a;  Iterate over the enrolments of the train set

        Yields dictionaries with the followings keys:

        * uri: str
          unique audio file identifier
        * database: str
          unique database identifier
        * model_id: str
          unique model identifier (the same speaker might have different models)
        * enrol_with: pyannote.core.Timeline
          parts of the audio file to use for enrolment

        as well as keys coming from the provided preprocessors (e.g. 'audio')

        Usage
        -----
        >>> models = {}
        >>> for enrolment in protocol.train_enrolment():
        ...     # obtain path to audio file
        ...     audio = enrolment['audio']
        ...     # obtain parts of the audio file to use for enrolment
        ...     enrol_with = enrolment['enrol_with']
        ...     # this is where enrolment actually happens
        ...     model = do_something(audio, enrol_with)
        ...     # store models for later use
        ...     model_id = enrolment['model_id']
        ...     models[model_id] = model

        N)r   
preprocessr   	generatorcurrent_enrolmentr	   r	   r
   train_enrolmentV   
    z'SpeakerSpottingProtocol.train_enrolmentc                 c   r   )aQ  Iterate over the trials of the train set

        Yields dictionaries with the followings keys:

        * uri: str
          unique audio file identifier
        * database: str
          unique database identifier
        * try_with: pyannote.core.Segment, optional
          parts of the audio file where to look for the target speaker.
          default is to use the whole audio file
        * model_id: str
          unique identifier of the target
        * reference: pyannote.core.Timeline
          parts of the audio file where the target actually speaks.
          it might be empty in case of impostor trials.
          in case of genuine trials, it should be contained in `try_with`

        as well as keys coming from the provided preprocessors (e.g. 'audio')

        Usage
        -----
        >>> for trial in protocol.train_trial():
        ...     # obtain path to audio file
        ...     audio = trial['audio']
        ...     # obtain parts of the audio file to use for trial
        ...     try_with = trial['try_with']
        ...     # this is where the trial actually happens
        ...     model_id = trial['model_id']
        ...     score = do_something(audio, try_with, model_id)
        ...     # optionally perform evaluation
        ...     reference = trial['reference']
        ...     metric(reference, score)

        N)r   r   r   r   current_trialr	   r	   r
   train_trial{   
   %z#SpeakerSpottingProtocol.train_trialc                 c   r   )aG  Iterate over the enrolments of the development set

        Yields dictionaries with the followings keys:

        * uri: str
          unique audio file identifier
        * database: str
          unique database identifier
        * model_id: str
          unique model identifier (the same speaker might have different models)
        * enrol_with: pyannote.core.Timeline
          parts of the audio file to use for enrolment

        as well as keys coming from the provided preprocessors (e.g. 'audio')

        Usage
        -----
        >>> models = {}
        >>> for enrolment in protocol.development_enrolment():
        ...     # obtain path to audio file
        ...     audio = enrolment['audio']
        ...     # obtain parts of the audio file to use for enrolment
        ...     enrol_with = enrolment['enrol_with']
        ...     # this is where enrolment actually happens
        ...     model = do_something(audio, enrol_with)
        ...     # store models for later use
        ...     model_id = enrolment['model_id']
        ...     models[model_id] = model

        N)r   r   r   r	   r	   r
   development_enrolment   r   z-SpeakerSpottingProtocol.development_enrolmentc                 c   r   )a]  Iterate over the trials of the development set

        Yields dictionaries with the followings keys:

        * uri: str
          unique audio file identifier
        * database: str
          unique database identifier
        * try_with: pyannote.core.Segment, optional
          parts of the audio file where to look for the target speaker.
          default is to use the whole audio file
        * model_id: str
          unique identifier of the target
        * reference: pyannote.core.Timeline
          parts of the audio file where the target actually speaks.
          it might be empty in case of impostor trials.
          in case of genuine trials, it should be contained in `try_with`

        as well as keys coming from the provided preprocessors (e.g. 'audio')

        Usage
        -----
        >>> for trial in protocol.development_trial():
        ...     # obtain path to audio file
        ...     audio = trial['audio']
        ...     # obtain parts of the audio file to use for trial
        ...     try_with = trial['try_with']
        ...     # this is where the trial actually happens
        ...     model_id = trial['model_id']
        ...     score = do_something(audio, try_with, model_id)
        ...     # optionally perform evaluation
        ...     reference = trial['reference']
        ...     metric(reference, score)

        N)r   r   r   r	   r	   r
   development_trial   r"   z)SpeakerSpottingProtocol.development_trialc                 c   r   )a9  Iterate over the enrolments of the test set

        Yields dictionaries with the followings keys:

        * uri: str
          unique audio file identifier
        * database: str
          unique database identifier
        * model_id: str
          unique model identifier (the same speaker might have different models)
        * enrol_with: pyannote.core.Timeline
          parts of the audio file to use for enrolment

        as well as keys coming from the provided preprocessors (e.g. 'audio')

        Usage
        -----
        >>> models = {}
        >>> for enrolment in protocol.test_enrolment():
        ...     # obtain path to audio file
        ...     audio = enrolment['audio']
        ...     # obtain parts of the audio file to use for enrolment
        ...     enrol_with = enrolment['enrol_with']
        ...     # this is where enrolment actually happens
        ...     model = do_something(audio, enrol_with)
        ...     # store models for later use
        ...     model_id = enrolment['model_id']
        ...     models[model_id] = model

        N)r   r   r   r	   r	   r
   test_enrolment   r   z&SpeakerSpottingProtocol.test_enrolmentc                 c   r   )aO  Iterate over the trials of the test set

        Yields dictionaries with the followings keys:

        * uri: str
          unique audio file identifier
        * database: str
          unique database identifier
        * try_with: pyannote.core.Segment, optional
          parts of the audio file where to look for the target speaker.
          default is to use the whole audio file
        * model_id: str
          unique identifier of the target
        * reference: pyannote.core.Timeline
          parts of the audio file where the target actually speaks.
          it might be empty in case of impostor trials.
          in case of genuine trials, it should be contained in `try_with`

        as well as keys coming from the provided preprocessors (e.g. 'audio')

        Usage
        -----
        >>> for trial in protocol.test_trial():
        ...     # obtain path to audio file
        ...     audio = trial['audio']
        ...     # obtain parts of the audio file to use for trial
        ...     try_with = trial['try_with']
        ...     # this is where the trial actually happens
        ...     model_id = trial['model_id']
        ...     score = do_something(audio, try_with, model_id)
        ...     # optionally perform evaluation
        ...     reference = trial['reference']
        ...     metric(reference, score)

        N)r   r   r   r	   r	   r
   
test_trial  r"   z"SpeakerSpottingProtocol.test_trialN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r   r   r!   r#   r$   r%   r&   r	   r	   r	   r
   r   !   s"    %*%*%r   N)speaker_diarizationr   r   r	   r	   r	   r
   <module>   s   