pyannote.database

6.1.1 · active · verified Thu Apr 09

pyannote.database is an open-source Python library that provides a common interface for reproducible experimental protocols across various multimedia databases (audio, video, text). It is part of the broader pyannote ecosystem. Currently at version 6.1.1, the library maintains an active development pace with several releases annually, including significant major version updates that introduce breaking changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a simple database protocol using a YAML configuration file, load it into the `pyannote.database` registry, and then iterate over a protocol subset to access multimedia resources and their associated metadata. It highlights the use of `registry.load_database` and `FileFinder`.

import os
from pathlib import Path
from pyannote.database import registry, FileFinder

# 1. Define your database protocol in a YAML file (e.g., database.yml)
# This example creates dummy files for demonstration purposes.
(Path("data") / "train.lst").parent.mkdir(parents=True, exist_ok=True)
(Path("data") / "train.lst").write_text("dummy_file_1\ndummy_file_2\n")

config_content = """
Protocols:
  MyDatabase:
    MyProtocol:
      train:
        uri: data/train.lst
"""
Path("database.yml").write_text(config_content)

# 2. Load the database configuration into the registry
# In a real scenario, you'd provide the actual path to your database.yml
# For demonstration, we ensure our dummy config is found.
os.environ["PYANNOTE_DATABASE_CONFIG"] = str(Path("database.yml").resolve())
registry.load_database("database.yml")

# 3. Access a specific protocol
# Use FileFinder as a preprocessor to resolve file paths for 'audio' or similar keys.
preprocessors = {'audio': FileFinder()}
protocol = registry.get_protocol("MyDatabase.MyProtocol", preprocessors=preprocessors)

# 4. Iterate over a subset (e.g., 'train') of the protocol
print("Iterating over training files:")
for current_file in protocol.train():
    print(f"  URI: {current_file['uri']}")
    # In a real application, current_file['audio'] would resolve to the media file path,
    # and current_file['annotation'] would provide temporal annotations.
    # For this dummy example, 'audio' will not resolve to a real file path
    # unless actual dummy audio files are created.

# 5. Clean up dummy files (not needed in a real application)
Path("database.yml").unlink()
(Path("data") / "train.lst").unlink()
Path("data").rmdir()

view raw JSON →