使用Python代码进行树莓派上的麦阵列声源定位

偶然发现seeedstudio更新了他们的英文版说明书,然而中文版还没更新[捂脸]。关于DOA的部分,除了原来的使用ODAS Studio的方法以外,又多加了一些使用Python代码直接进行DOA的章节。

0 安装驱动

别忘了用source activate doa切到专门的环境里,或者conda create -n doa python=3.6现造一个环境。

安装驱动:

1
2
3
4
proxychains4 git clone https://github.com/respeaker/seeed-voicecard.git
cd seeed-voicecard
sudo proxychains4 ./install.sh
sudo reboot -h now

检查驱动:

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
arecord -L # 输入驱动,即录制
null
Discard all samples (playback) or generate zero samples (capture)
default
ac108
dmixer
ac101
sysdefault:CARD=seeed8micvoicec
seeed-8mic-voicecard,
Default Audio Device
dmix:CARD=seeed8micvoicec,DEV=0
seeed-8mic-voicecard,
Direct sample mixing device
dsnoop:CARD=seeed8micvoicec,DEV=0
seeed-8mic-voicecard,
Direct sample snooping device
hw:CARD=seeed8micvoicec,DEV=0
seeed-8mic-voicecard,
Direct hardware device without any conversions
plughw:CARD=seeed8micvoicec,DEV=0
seeed-8mic-voicecard,
Hardware device with all software conversions

aplay -L # 输出驱动,即播放
null
Discard all samples (playback) or generate zero samples (capture)
default
ac108
dmixer
ac101
sysdefault:CARD=ALSA
bcm2835 ALSA, bcm2835 ALSA
Default Audio Device
dmix:CARD=ALSA,DEV=0
bcm2835 ALSA, bcm2835 ALSA
Direct sample mixing device
dmix:CARD=ALSA,DEV=1
bcm2835 ALSA, bcm2835 IEC958/HDMI
Direct sample mixing device
dsnoop:CARD=ALSA,DEV=0
bcm2835 ALSA, bcm2835 ALSA
Direct sample snooping device
dsnoop:CARD=ALSA,DEV=1
bcm2835 ALSA, bcm2835 IEC958/HDMI
Direct sample snooping device
hw:CARD=ALSA,DEV=0
bcm2835 ALSA, bcm2835 ALSA
Direct hardware device without any conversions
hw:CARD=ALSA,DEV=1
bcm2835 ALSA, bcm2835 IEC958/HDMI
Direct hardware device without any conversions
plughw:CARD=ALSA,DEV=0
bcm2835 ALSA, bcm2835 ALSA
Hardware device with all software conversions
plughw:CARD=ALSA,DEV=1
bcm2835 ALSA, bcm2835 IEC958/HDMI
Hardware device with all software conversions
sysdefault:CARD=seeed8micvoicec
seeed-8mic-voicecard,
Default Audio Device
dmix:CARD=seeed8micvoicec,DEV=0
seeed-8mic-voicecard,
Direct sample mixing device
dsnoop:CARD=seeed8micvoicec,DEV=0
seeed-8mic-voicecard,
Direct sample snooping device
hw:CARD=seeed8micvoicec,DEV=0
seeed-8mic-voicecard,
Direct hardware device without any conversions
plughw:CARD=seeed8micvoicec,DEV=0
seeed-8mic-voicecard,
Hardware device with all software conversions

1 测试LED

说实话,自打买了这个麦阵列,我还从来没试过这12个LED灯[捂脸],试试吧要不感觉对不起这个板子,另外,运行demo需要gpiozerospidevpyusb

1
2
3
4
5
proxychains4 git clone --depth 1 https://github.com/respeaker/pixel_ring.git
cd pixel_ring
proxychains4 pip install -U -e .
proxychains4 pip install gpiozero RPi.GPIO
python examples/respeaker_4mic_array.py

控制LED的主要代码其实就在函数show(),直接在Python交互环境中输入下面的代码,就可以打开12点方向的灯,并渲染为白色,也就是ARGB(0, 64, 64, 64)。

1
2
3
4
5
6
7
8
from pixel_ring import pixel_ring
from gpiozero import LED

power = LED(5)
power.on()

pixel_ring.set_brightness(10) # 0-100,其实会被转换为`APA102.dev.global_brightness`的0-31
pixel_ring.pattern.show([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 64, 64])

用于控制的数组是一个48位的list,从1点钟方向开始,到12点钟方向结束,每四位控制一个LED灯,非常好操作。

2 装DOA相关库

添加seeed提供的apt源。(靠谱的公司啊)

1
2
3
echo "deb https://seeed-studio.github.io/pi_repo/ stretch main" | sudo tee /etc/apt/sources.list.d/seeed.list
proxychains4 curl https://seeed-studio.github.io/pi_repo/public.key | sudo apt-key add -
proxychains4 sudo apt update

安装numpypyaudio

1
2
3
proxychains4 conda install -y numpy
proxychains4 sudo apt-get install -y portaudio19-dev
proxychains4 pip install pyaudio

安装编译工具:

1
sudo proxychains4 apt-get install -y swig python-dev libatlas-base-dev build-essential make

安装snowboy(热词检测DOA):

1
2
3
4
5
proxychains4 git clone --depth 1 https://github.com/Kitt-AI/snowboy.git
cd snowboy
python setup.py build
python setup.py bdist_wheel
pip install dist/snowboy*.whl

安装seeed的voice-engin

1
2
3
4
proxychains4 git clone https://github.com/voice-engine/voice-engine.git
cd voice-engine
python setup.py bdist_wheel
pip install dist/*.whl

测试ok~:

1
python ~/doa/voice-engine/examples/respeaker_6mic_array_for_pi/kws_doa.py

如果只是想用DOA功能,可以试试seeed的老项目mic_array

1
2
proxychains4 git clone https://github.com/respeaker/mic_array.git
python ./mic_array/mic_array.py

对比了一下,跟人家introlab/odas项目差的还是比较远的。直观上看就是我们简单的靠fft实现的DOA仅仅能做到平面范围内的方位判断,仅输出一个角度(平面offset),速度慢且不支持声源跟踪等功能。而odas的声源定位项目输出两个值,一个平面offset一个法向offset,还能进行声源分辨,多声源跟踪跟踪。odas项目的理论收录在Lightweight and Optimized Sound Source Localization and Tracking Methods for Opened and Closed Microphone Array Configurations中,值得一读。

评论

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×