pyannote-core

6.0.1 · active · verified Thu Apr 09

pyannote.core is an open-source Python library providing advanced data structures for handling temporal segments with attached labels. It serves as the foundational component for the broader pyannote ecosystem, which includes libraries for parsing, metrics, databases, audio, and video processing. The library facilitates the manipulation and visualization of temporal data, especially useful in speech processing and diarization tasks. The current version is 6.0.1, part of an actively developed project with a history of significant updates and breaking changes between major releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the creation and basic manipulation of the core data structures: Segment, Timeline, and Annotation. It shows how to define temporal intervals, combine them into an ordered set, and attach labels to segments.

from pyannote.core import Segment, Timeline, Annotation

# 1. Create a Segment (start, end)
s1 = Segment(0.0, 10.0)
s2 = Segment(12.5, 15.0)
print(f"Segment 1: {s1}")
print(f"Duration of s1: {s1.duration:.1f}s\n")

# 2. Create a Timeline (ordered set of non-empty segments)
timeline = Timeline([s1, s2, Segment(1.0, 5.0)], uri="meeting_audio")
print(f"Initial Timeline: {timeline}")
timeline = timeline.support()
print(f"Unified Timeline support: {timeline}\n")

# 3. Create an Annotation (segments with attached labels/tracks)
annotation = Annotation(uri="meeting_audio")
annotation[Segment(0.5, 3.0)] = "Speaker_A"
annotation[Segment(2.0, 4.5)] = "Speaker_B"
annotation[Segment(5.0, 7.0), "music"] = "Background_Music"
print(f"Annotation labels: {annotation.labels()}")
print(f"Annotation timeline for Speaker_A: {annotation.label_timeline('Speaker_A')}")

view raw JSON →