Ë
      çi„  ã                   óN   — d dl mZmZ ddlmZ ddlmZ ddlmZ  G d„ de«      Zy)	é    )ÚDictÚIteratoré   )ÚSpeakerDiarizationProtocol)ÚSubset)ÚLEGACY_SUBSET_MAPPINGc                   ó’   — e Zd ZdZdedee   fd„Zdee   fd„Zdee   fd„Z	dee   fd„Z
dee   fd„Zdee   fd	„Zdee   fd
„Zy)ÚSpeakerVerificationProtocola  A protocol for speaker verification experiments

    A speaker verification protocol can be defined programmatically by creating
    a class that inherits from `SpeakerVerificationProtocol` and implement at
    least one of `train_trial_iter`, `development_trial_iter` and
    `test_trial_iter` methods:

        >>> class MySpeakerVerificationProtocol(SpeakerVerificationProtocol):
        ...     def train_trial_iter(self) -> Iterator[Dict]:
        ...         yield {"reference": 0,
        ...                "file1": {
        ...                     "uri":"filename1",
        ...                     "try_with":Timeline(...)
        ...                },
        ...                "file2": {
        ...                     "uri":"filename3",
        ...                     "try_with":Timeline(...)
        ...                },
        ...         }

    `{subset}_trial_iter` should return an iterator of dictionnaries with

    - `reference` key (mandatory) that provides an int portraying whether
      `file1` and `file2` are uttered by the same speaker (1 is same, 0 is
      different),
    - `file1` key (mandatory) that provides the first file,
    - `file2` key (mandatory) that provides the second file.

    Both `file1` and `file2` should be provided as dictionaries or ProtocolFile
    instances with

    - `uri` key (mandatory),
    - `try_with` key (mandatory) that describes which part of the file should
      be used in the validation process, as a `pyannote.core.Timeline` instance.
    - any other key that the protocol may provide.

    It can then be used in Python like this:

        >>> protocol = MySpeakerVerificationProtocol()
        ... for trial in protocol.train_trial():
        ...     print(f"{trial['reference']} {trial['file1']['uri']} {trial['file2']['uri']}")
        1 filename1 filename2
        0 filename1 filename3

    A speaker verification protocol can also be defined using `pyannote.database`
    configuration file, whose (configurable) path defaults to "~/database.yml".

    ~~~ Content of ~/database.yml ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Protocols:
        MyDatabase:
        SpeakerVerification:
            MyProtocol:
            train:
                uri: /path/to/train.lst
                duration: /path/to/duration.map
                trial: /path/to/trial.txt
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    where `/path/to/train.lst` contains the list of identifiers of the
    files in the collection:

    ~~~ Content of /path/to/train.lst~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    filename1
    filename2
    filename3
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    `/path/to/duration.map` contains the duration of the files:

    ~~~ Content of /path/to/duration.map ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    filename1 30.000
    filename2 30.000
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    `/path/to/trial.txt` contains a list of trials :

    ~~~ Content of /path/to/trial ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1 filename1 filename2
    0 filename1 filename3
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    `1` stands for _target_ trials and `0` for _non-target_ trials.
    In the example below, it means that the same speaker uttered files
    `filename1` and `filename2` and that `filename1` and `filename3` are from
    two different speakers.

    It can then be used in Python like this:

        >>> from pyannote.database import registry
        >>> protocol = registry.get_protocol('MyDatabase.SpeakerVerification.MyProtocol')
        >>> for trial in protocol.train_trial():
        ...     print(f"{trial['reference']} {trial['file1']['uri']} {trial['file2']['uri']}")
        1 filename1 filename2
        0 filename1 filename3

    Note that speaker verification protocols (`SpeakerVerificationProtocol`)
    are a subclass of speaker diarization protocols (`SpeakerDiarizationProtocol`).
    As such, they also define regular `{subset}` methods.
    ÚsubsetÚreturnc              #   óJ  K  — 	  t        | |› d�«      «       }|D ]4  }| j	                  |d   «      |d<   | j	                  |d   «      |d<   |–— Œ6 y # t        t        f$ r? t        |   }	  t        | |› d�«      «       }n# t        $ r |› d�}t        |«      ‚w xY wY Œ‡w xY w­w)NÚ_trial_iterÚ	_try_iterz_trial_iter is not implemented.Úfile1Úfile2)ÚgetattrÚAttributeErrorÚNotImplementedErrorr   Ú
preprocess)Úselfr   ÚtrialsÚsubset_legacyÚmsgÚtrials         ú„/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/pyannote/database/protocol/speaker_verification.pyÚsubset_trial_helperz/SpeakerVerificationProtocol.subset_trial_helper‰   sË   è ø€ ð	*Ø:”W˜T f X¨[Ð#9Ó:Ó<ˆFó ˆEØ!Ÿ_™_¨U°7©^Ó<ˆE�'‰NØ!Ÿ_™_¨U°7©^Ó<ˆE�'‰NØ‹Kñ øô Ô 3Ð4ò 	*ô 2°&Ñ9ˆMð*ØCœ ¨-¨¸	Ð'BÓCÓE‘øÜ!ò *Ø˜Ð ?Ð@�Ü$ SÓ)Ð)ð*úñ ð	*üs?   ‚B#„A ˜:B#ÁB Á+B Á?B Â BÂB ÂB#ÂB Â B#c                 ó   — t        «       ‚)z'Iterate over trials in the train subset©r   ©r   s    r   Útrain_trial_iterz,SpeakerVerificationProtocol.train_trial_iterŸ   ó   € ä!Ó#Ð#ó    c                 ó   — t        «       ‚)z-Iterate over trials in the development subsetr   r   s    r   Údevelopment_trial_iterz2SpeakerVerificationProtocol.development_trial_iter£   r!   r"   c                 ó   — t        «       ‚)z&Iterate over trials in the test subsetr   r   s    r   Útest_trial_iterz+SpeakerVerificationProtocol.test_trial_iter§   r!   r"   c                 ó$   — | j                  d«      S )NÚtrain©r   r   s    r   Útrain_trialz'SpeakerVerificationProtocol.train_trial«   s   € Ø×'Ñ'¨Ó0Ð0r"   c                 ó$   — | j                  d«      S )NÚdevelopmentr)   r   s    r   Údevelopment_trialz-SpeakerVerificationProtocol.development_trial®   s   € Ø×'Ñ'¨Ó6Ð6r"   c                 ó$   — | j                  d«      S )NÚtestr)   r   s    r   Ú
test_trialz&SpeakerVerificationProtocol.test_trial±   s   € Ø×'Ñ'¨Ó/Ð/r"   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r    r$   r&   r*   r-   r0   © r"   r   r
   r
   $   s€   „ ñbðH¨&ð °X¸d±^ó ð,$ (¨4¡.ó $ð$¨°©ó $ð$ ¨$¡ó $ð1˜X d™^ó 1ð7 8¨D¡>ó 7ð0˜H T™Nô 0r"   r
   N)	Útypingr   r   Úspeaker_diarizationr   Úprotocolr   r   r
   r5   r"   r   Ú<module>r9      s"   ð÷< "Ý ;Ý Ý +ôN0Ð"<õ N0r"   