-
Notifications
You must be signed in to change notification settings - Fork 2
/
e3.ds_ns_kws.py
61 lines (42 loc) · 1.46 KB
/
e3.ds_ns_kws.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
54
55
56
57
58
59
60
61
"""
A example to show delay&sum beamforming, Noise Suppression (NS) and Keyword Spotting (KWS)
The keyword is "computer".
Requirements:
snowboy - https://github.com/Kitt-AI/snowboy
python-webrtc-audio-processing - `pip3 install webrtc-audio-processing`
"""
import time
import numpy as np
from voice_engine.element import Element
from voice_engine.source import Source
from voice_engine.kws import KWS
from voice_engine.ns import NS
class DelaySum(Element):
'''a simplest delay&sum beamforming with zero delay'''
def __init__(self, channels=4):
super(DelaySum, self).__init__()
self.channels = channels
def put(self, data):
data = np.fromstring(data, dtype='int16')
bf = data[0::self.channels] / self.channels
for ch in range(1, self.channels):
bf += data[ch::self.channels] / self.channels
super(DelaySum, self).put(bf.astype('int16').tostring())
def main():
src = Source(rate=16000, channels=4, device_name="default")
ds = DelaySum(channels=src.channels)
ns = NS(rate=16000, channels=1)
kws = KWS(model='computer', sensitivity=0.6, verbose=True)
src.pipeline(ds, ns, kws)
def on_detected(keyword):
print('\ndetected {}'.format(keyword))
kws.set_callback(on_detected)
src.pipeline_start()
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
break
src.pipeline_stop()
if __name__ == '__main__':
main()