diff --git a/CHANGELOG.md b/CHANGELOG.md index 95a90213..dad38079 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## Next + +- feat(sample): add transcription of sample file + ## Version 4.0.3 (2025-12-07) - feat(cli): add `--revision` option to most CLI commands diff --git a/src/pyannote/audio/sample/__init__.py b/src/pyannote/audio/sample/__init__.py index 85399af6..c9fe5136 100644 --- a/src/pyannote/audio/sample/__init__.py +++ b/src/pyannote/audio/sample/__init__.py @@ -1,6 +1,7 @@ # MIT License # -# Copyright (c) 2024- CNRS +# Copyright (c) 2024-2025 CNRS +# Copyright (c) 2026- pyannoteAI # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -23,34 +24,56 @@ from pathlib import Path +from pyannote.audio.core.io import Audio, AudioFile from pyannote.core import Annotation, Segment, Timeline from pyannote.database.util import load_rttm -from pyannote.audio.core.io import Audio, AudioFile + +def load_stm(file_stm: str | Path) -> dict[str, list[dict]]: + session_ids = {} + + with open(file_stm, "r") as stm: + for line in stm: + infos = line.strip().split() + session_id, _, spk, start, end, *words = infos + + entry = { + "start": float(start), + "end": float(end), + "text": " ".join(words), + "speaker": spk, + } + + session_ids.setdefault(session_id, []).append(entry) + + return session_ids -def _sample() -> AudioFile: - sample_wav = Path(__file__).parent / "sample.wav" - uri = "sample" +def _sample(uri: str = "sample") -> AudioFile: + sample_wav = Path(__file__).parent / f"{uri}.wav" audio = Audio() waveform, sample_rate = audio(sample_wav) - sample_rttm = Path(__file__).parent / "sample.rttm" - - annotation: Annotation = load_rttm(sample_rttm)[uri] + sample_rttm = Path(__file__).parent / f"{uri}.rttm" + diarization: Annotation = load_rttm(sample_rttm)[uri] duration = audio.get_duration(sample_wav) annotated: Timeline = Timeline([Segment(0.0, duration)], uri=uri) + sample_stm = Path(__file__).parent / f"{uri}.stm" + transcription = load_stm(sample_stm)[uri] + return { "audio": sample_wav, - "uri": "sample", + "uri": uri, "waveform": waveform, "sample_rate": sample_rate, - "annotation": annotation, + "annotation": diarization, "annotated": annotated, + "diarization": diarization, + "transcription": transcription, } -SAMPLE_FILE = _sample() +SAMPLE_FILE = _sample(uri="sample") diff --git a/src/pyannote/audio/sample/sample.stm b/src/pyannote/audio/sample/sample.stm new file mode 100644 index 00000000..3b599906 --- /dev/null +++ b/src/pyannote/audio/sample/sample.stm @@ -0,0 +1,13 @@ +sample 1 Diane 6.68 7.16 Hello? +sample 1 Sheila 7.634 8.155 Hello? +sample 1 Diane 8.436 8.876 Oh, hello. +sample 1 Diane 8.916 9.798 I didn't know you were there. +sample 1 Sheila 9.838 10.78 Neither did I. +sample 1 Diane 10.78 12.54 Okay, then I thought you know, I heard a beep. +sample 1 Diane 12.542 14.184 This is Diane in New Jersey. +sample 1 Sheila 14.444 17.769 And I'm Sheila in Texas, originally from Chicago. +sample 1 Diane 17.789 20.113 Oh, I'm originally from Chicago also. +sample 1 Diane 20.173 21.475 I'm in New Jersey now though. +sample 1 Sheila 21.935 23.978 Well, there isn't that much difference. +sample 1 Sheila 24.058 28.425 At least you know, they all call me a Yankee down here, so what can I say? +sample 1 Diane 28.445 29.987 Oh, I don't hear that in New Jersey now.