pyannote-core
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
- breaking Version 6.0.0 introduced breaking changes, including dropping support for Python versions older than 3.10 and switching to a native namespace package structure. Ensure your environment meets the new Python requirement and update import mechanisms if relying on non-standard package structures.
- breaking The `pyannote.core.Scores` class and related functionalities were removed in version 3.3. If your code depends on `pyannote.core.Scores` for handling scores over time, you will need to refactor it, potentially using `pyannote.core.SlidingWindowFeature` or custom data structures.
- breaking As of version 4.4, `Timeline.__init__` no longer accepts empty segments (where `start >= end`). Additionally, `Timeline.extent()` now returns `Segment(0.0, 0.0)` for empty timelines, affecting how edge cases for empty data are handled.
- gotcha Floating-point precision issues can lead to inconsistencies when comparing `Segment` instances. It is highly recommended to call `Segment.set_precision(ndigits)` once after importing `pyannote.core.Segment` to globally round start and end timestamps to a consistent precision.
Install
-
pip install pyannote-core -
pip install pyannote-core[notebook]
Imports
- Segment
from pyannote.core import Segment
- Timeline
from pyannote.core import Timeline
- Annotation
from pyannote.core import Annotation
- SlidingWindow
from pyannote.core import SlidingWindow
- SlidingWindowFeature
from pyannote.core import SlidingWindowFeature
Quickstart
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')}")