diff --git a/CHANGELOG.md b/CHANGELOG.md index 29e5dc31..15b5b6ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - feat(task): add option to cache task training metadata to speed up training - feat(pipeline): add `Waveform` and `SampleRate` preprocessors - feat(model): add `num_frames`, `receptive_field`, and `dimension` properties to segmentation models +- feat(sample): add sample file at `pyannote.audio.sample.SAMPLE_FILE` ### Fixes diff --git a/MANIFEST.in b/MANIFEST.in index 16909925..45ad7d6a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,6 @@ recursive-include pyannote *.py recursive-include pyannote *.yaml +recursive-include pyannote *.wav +recursive-include pyannote *.rttm global-exclude *.pyc global-exclude __pycache__ diff --git a/pyannote/audio/sample/__init__.py b/pyannote/audio/sample/__init__.py new file mode 100644 index 00000000..85399af6 --- /dev/null +++ b/pyannote/audio/sample/__init__.py @@ -0,0 +1,56 @@ +# MIT License +# +# Copyright (c) 2024- CNRS +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +from pathlib import Path + +from pyannote.core import Annotation, Segment, Timeline +from pyannote.database.util import load_rttm + +from pyannote.audio.core.io import Audio, AudioFile + + +def _sample() -> AudioFile: + sample_wav = Path(__file__).parent / "sample.wav" + uri = "sample" + + audio = Audio() + waveform, sample_rate = audio(sample_wav) + + sample_rttm = Path(__file__).parent / "sample.rttm" + + annotation: Annotation = load_rttm(sample_rttm)[uri] + duration = audio.get_duration(sample_wav) + + annotated: Timeline = Timeline([Segment(0.0, duration)], uri=uri) + + return { + "audio": sample_wav, + "uri": "sample", + "waveform": waveform, + "sample_rate": sample_rate, + "annotation": annotation, + "annotated": annotated, + } + + +SAMPLE_FILE = _sample() diff --git a/pyannote/audio/sample/sample.rttm b/pyannote/audio/sample/sample.rttm new file mode 100644 index 00000000..7c6b378f --- /dev/null +++ b/pyannote/audio/sample/sample.rttm @@ -0,0 +1,10 @@ +SPEAKER sample 1 6.690 0.430 speaker90 +SPEAKER sample 1 7.550 0.800 speaker91 +SPEAKER sample 1 8.320 1.700 speaker90 +SPEAKER sample 1 9.920 1.110 speaker91 +SPEAKER sample 1 10.570 4.130 speaker90 +SPEAKER sample 1 14.490 3.430 speaker91 +SPEAKER sample 1 18.050 3.440 speaker90 +SPEAKER sample 1 18.150 0.440 speaker91 +SPEAKER sample 1 21.780 6.720 speaker91 +SPEAKER sample 1 27.850 2.150 speaker90 diff --git a/pyannote/audio/sample/sample.wav b/pyannote/audio/sample/sample.wav new file mode 100644 index 00000000..150d49a6 Binary files /dev/null and b/pyannote/audio/sample/sample.wav differ diff --git a/tests/test_sample.py b/tests/test_sample.py new file mode 100644 index 00000000..d47dc961 --- /dev/null +++ b/tests/test_sample.py @@ -0,0 +1,28 @@ +# The MIT License (MIT) +# +# Copyright (c) 2024- CNRS +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +def test_sample(): + from pyannote.audio.sample import SAMPLE_FILE + + assert "annotation" in SAMPLE_FILE + assert "annotated" in SAMPLE_FILE