Open-source X Spaces transcription.

Star

44 lines · 1.2 KB

python
1from __future__ import annotations
2
3import sys
4from pathlib import Path
5
6sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
7
8from space_tape.merge import attach_speakers
9
10
11def test_midpoint_assignment() -> None:
12 regions = [
13 {"start": 0.0, "end": 4.0, "speaker": "notpierce69"},
14 {"start": 4.0, "end": 8.0, "speaker": "djay44444"},
15 {"start": 8.0, "end": 10.0, "speaker": "both"},
16 ]
17 cues = [
18 {"start": 1.0, "end": 3.0, "text": "Hey DJ"},
19 {"start": 4.5, "end": 6.5, "text": "yeah"},
20 {"start": 8.2, "end": 9.1, "text": "overlap"},
21 ]
22 out = attach_speakers(cues, regions)
23 assert [c["speaker"] for c in out] == ["notpierce69", "djay44444", "both"]
24
25
26def test_silence_becomes_unknown() -> None:
27 regions = [{"start": 0.0, "end": 5.0, "speaker": "silence"}]
28 cues = [{"start": 1.0, "end": 2.0, "text": "hmm"}]
29 out = attach_speakers(cues, regions)
30 assert out[0]["speaker"] == "unknown"
31
32
33def test_empty_regions() -> None:
34 cues = [{"start": 0.0, "end": 1.0, "text": "hi"}]
35 out = attach_speakers(cues, [])
36 assert out[0]["speaker"] == "unknown"
37
38
39if __name__ == "__main__":
40 test_midpoint_assignment()
41 test_silence_becomes_unknown()
42 test_empty_regions()
43 print("ok")