-
Notifications
You must be signed in to change notification settings - Fork 17
/
ns_vs_raw.py
53 lines (39 loc) · 1.17 KB
/
ns_vs_raw.py
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
"""
Compare Keyword Search (KWS) between audio with Noise Suppresion (NS) and raw audio.
The keyword is "snowboy". Channel 0 has NS, channel 1 doesn't.
"""
import time
from voice_engine.source import Source
from voice_engine.route import Route
from voice_engine.ns import NS
from voice_engine.kws import KWS
def main():
src = Source(rate=16000, channels=2)
route = Route(channels=src.channels)
ns = NS(rate=16000, channels=1)
def get_kws_callback(channel):
def on_detected(keyword):
print('detected @ {}'.format(channel))
return on_detected
kws = []
for channel in range(2):
k = KWS(model='snowboy', sensitivity=0.6, verbose=False)
k.on_detected = get_kws_callback(channel)
kws.append(k)
# data flow between elements
# ---------------------------
# src -> route -> ns -> kws[0]
# \
# kws[1]
src.link(route)
route.link((ns, kws[1]))
ns.link(kws[0])
src.recursive_start()
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
break
src.recursive_stop()
if __name__ == '__main__':
main()