Skip to content

Commit 7e698cb

Browse files
authored
feat: add Annotation.__iter__ (turn: Segment, speaker: str) iterator (#104)
1 parent 0e7b94e commit 7e698cb

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## Version 6.0.1 (wip)
4+
5+
- feat: add `Annotation.__iter__` (turn: Segment, speaker: str) iterator
6+
37
## Version 6.0.0 (2025-09-09)
48

59
- BREAKING: drop support to `Python` < 3.10

src/pyannote/core/annotation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,18 @@ def __bool__(self):
247247
"""
248248
return len(self._tracks) > 0
249249

250+
def __iter__(self) -> Iterator[Tuple[Segment, Label]]:
251+
"""Iterate over (segment, label) pairs in chronological order
252+
253+
Examples
254+
--------
255+
256+
>>> for segment, label in annotation:
257+
... # do something with the segment and its label
258+
"""
259+
for segment, _, label in self.itertracks(yield_label=True):
260+
yield segment, label
261+
250262
def itersegments(self):
251263
"""Iterate over segments (in chronological order)
252264

0 commit comments

Comments
 (0)