"""話者分離の呼び出し口。 pyannote は 3 系と 4 系で引数名も戻り値の形も違い、4 系は音声の読み込みに torchcodec を要求する。モデル本体は動かさず、その差を吸収できているかを確かめる。 """ import struct import sys import wave from pathlib import Path import pytest sys.path.insert(0, str(Path(__file__).resolve().parents[1])) import pipeline as pl # noqa: E402 class FakeTurn: def __init__(self, start, end): self.start, self.end = start, end class FakeAnnotation: """pyannote 3 系がそのまま返してくるもの。""" def __init__(self, rows): self.rows = rows def itertracks(self, yield_label=False): for start, end, label in self.rows: yield FakeTurn(start, end), None, label class FakeDiarizeOutput: """pyannote 4 系が返す入れ物。中に Annotation が入っている。""" def __init__(self, annotation): self.speaker_diarization = annotation ROWS = [(0.0, 8.5, "SPEAKER_00"), (8.5, 14.5, "SPEAKER_01")] @pytest.fixture def wav(tmp_path) -> Path: """16kHz モノラル 16bit の、1秒ぶんの WAV。""" path = tmp_path / "sample.wav" with wave.open(str(path), "wb") as f: f.setnchannels(1) f.setsampwidth(2) f.setframerate(16000) f.writeframes(b"".join(struct.pack("