forked from spokestack/spokestack-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_activation_timeout.py
More file actions
88 lines (64 loc) · 2.06 KB
/
test_activation_timeout.py
File metadata and controls
88 lines (64 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
This module contains the tests for the activation timeout class
"""
from spokestack.activation_timeout import ActivationTimeout
from spokestack.context import SpeechContext
def test_timeout_vad_fall():
max_active = 500
min_active = 20
context = SpeechContext()
timeout = ActivationTimeout(min_active=min_active, max_active=max_active)
context.is_active = True
context.is_speech = False
timeout(context)
context.is_speech = True
timeout(context)
assert context.is_active
context.is_speech = False
steps_before_timeout = (min_active // 20) + 2
for _ in range(steps_before_timeout):
timeout(context)
assert not context.is_active
timeout.close()
def test_max_active():
max_active = 500
min_active = 20
context = SpeechContext()
timeout = ActivationTimeout(min_active=min_active, max_active=max_active)
context.is_active = True
steps_before_timeout = (max_active // 20) + 1
for _ in range(steps_before_timeout):
timeout(context)
assert not context.is_active
timeout.close()
def test_min_active():
max_active = 500
min_active = 120
context = SpeechContext()
timeout = ActivationTimeout(min_active=min_active, max_active=max_active)
context.is_active = True
# call with speech active
context.is_speech = True
timeout(context)
# call timeout after speech is no longer detected
context.is_speech = False
timeout(context)
assert context.is_active
# vad fall should be True
# with context still active
timeout(context)
assert context.is_active
# context should remain active until min active
steps_before_deactivate = min_active // 20
for _ in range(steps_before_deactivate):
timeout(context)
assert context.is_active
# call with speech active
context.is_speech = True
timeout(context)
# call timeout after speech is no longer detected
# min active should be satisfied
context.is_speech = False
timeout(context)
assert not context.is_active
timeout.close()