"""The pause labels used to score real phone calls.""" import numpy as np import calls def test_hold_shift_and_backchannel(): # A speaks A again (hold) B answers (shift) A "mhm" B again starts = [0.0, 3.0, 6.0, 9.0, 10.0] ends = [2.0, 5.0, 8.0, 9.3, 12.0] speakers = ["A", "A", "B", "A", "B"] assert calls.pauses(starts, ends, speakers) == [(2.0, False), (5.0, True)] # The pause after B (8.0) is followed by a short "mhm" from A, and the pause at 9.3 follows that # "mhm": neither says whether a turn ended. def test_short_gaps_and_overlaps_are_left_out(): # 0.3 s gap: too short. Then A and B overlap right before the next pause: unclear who held the floor. starts = [0.0, 2.3, 4.0, 4.5, 8.0] ends = [2.0, 4.2, 6.0, 6.1, 10.0] speakers = ["A", "A", "B", "A", "B"] assert calls.pauses(starts, ends, speakers) == [] def test_upsampling_doubles_the_length(): tone = np.sin(2 * np.pi * 440 * np.arange(8000) / 8000).astype(np.float32) wide = calls.to_16k(tone[:, None], 8000) assert wide.size == 16000 and wide.dtype == np.float32 assert abs(np.abs(wide[2000:14000]).max() - 1.0) < 0.02