Sound source localization is where the sound is heard, and imagine stereophonic sound or binaural recording. By localizing the sound source for stereophonic sound, you can feel that the instrument can be heard from behind.
This time, we will use ReSpeaker Mic Array v2.0.
Basically all the usage and other options are written here, but I will briefly summarize them.
ubuntu 18.04 python3
sudo apt-get update
sudo pip install pyusb click
git clone https://github.com/respeaker/usb_4_mic_array.git
cd usb_4_mic_array
sudo python dfu.py --download 6_channels_firmware.bin
I think the usb_4_mic_array folder has been created. Create and execute the following code under this.
DOA.py
from tuning import Tuning
import usb.core
import usb.util
import time
dev = usb.core.find(idVendor=0x2886, idProduct=0x0018)
if dev:
Mic_tuning = Tuning(dev)
print(Mic_tuning.direction)
while True:
try:
print(Mic_tuning.direction)
time.sleep(1)
except KeyboardInterrupt:
break
Output result ↓
~/usb_4_mic_array$ python3 DOA.py
122
121
120
122
When I ran this code ImportError: No module named usb.core When it comes out
sudo apt-get install python-usb python3-usb
To execute.
Also, if permission denied, udev will give you device access.
sudo touch /etc/udev/rules.d/10-any_name_is_ok.rules
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="2886", ATTR{idProduct}=="0018", MODE="0666", GROUP="plugdev"' | sudo tee 10-any_name_is_ok.rules
sudo gpasswd -a username plugdev
sudo chmod a+r /etc/udev/rules.d/10-any_name_is_ok.rules
sudo udevadm control --reload-rules
udevadm trigger
After this, it will be reflected when you restart.
There are many options for ReSpeaker. [Optional Parameter List (Frequently Asked Questions Q1)] (https://wiki.seeedstudio.com/ReSpeaker_Mic_Array_v2.0/#faq)
As an example, we will use SPEECHDETECTED to implement sound source localization with only human voice. 0 = false (no speech detected) 1 = true (speech detected) So, modify DOA.py as follows.
voise_angle.py
from tuning import Tuning
import usb.core
import usb.util
import time
dev = usb.core.find(idVendor=0x2886, idProduct=0x0018)
if dev:
Mic_tuning = Tuning(dev)
while True:
try:
if Mic_tuning.read('SPEECHDETECTED') == 1:
print(Mic_tuning.direction)
time.sleep(1)
except KeyboardInterrupt:
break
With this, you can prevent the angle from being output even if you clap your hand, for example.
Since these codes use usb_4_mic_array / Tuning.py, you need to put Tuning.py in a folder or write the function of Tuning.py in the code to execute it outside this folder.
Here is an example of rewriting so that it can be used in any folder.
get_angle.py
from time import sleep
import usb
import usb.core
import usb.util
import struct
dev = usb.core.find(idVendor=0x2886,idProduct=0x0018)
TIMEOUT = 100000
# PARAMETERS for sound localization
PARAMETERS = {
'DOAANGLE': (21, 0, 'int', 359, 0, 'ro', 'DOA angle. Current value. Orientation depends on build configuration.'),
'SPEECHDETECTED': (19, 22, 'int', 1, 0, 'ro', 'Speech detection status.', '0 = false (no speech detected)',
'1 = true (speech detected)'),
}
def read(param_name):
try:
data = PARAMETERS[param_name]
except KeyError:
return
id = data[0]
cmd = 0x80 | data[1]
if data[2] == 'int':
cmd |= 0x40
length = 8
response = dev.ctrl_transfer(
usb.util.CTRL_IN | usb.util.CTRL_TYPE_VENDOR | usb.util.CTRL_RECIPIENT_DEVICE,
0, cmd, id, length, TIMEOUT)
response = struct.unpack(b'ii', response.tostring())
if data[2] == 'int':
result = response[0]
else:
result = response[0] * (2. ** response[1])
return result
# Find angular
if dev:
while True:
if read('SPEECHDETECTED') == 1:
print(read('DOAANGLE'))
sleep(1)
With this, you can localize the sound source under any folder.
Do the following wherever you like (either at home or in usb_4_mic_array)
python
git clone https://github.com/respeaker/pixel_ring.git
cd pixel_ring
sudo python setup.py install
sudo python examples/usb_mic_array.py
When you do this, How to wake up for 3 seconds How to shine think for 3 seconds speak 6 seconds to shine off How to shine for 3 seconds To do. Please refer to pixel_ring / pixel_ring / usb_pixel_ring_v2.py for other ways of lighting.
Recommended Posts