赞
踩
参考自:https://wiki.seeedstudio.com/ReSpeaker_Mic_Array_v2.0/#doa-direction-of-arrival
https://wiki.seeedstudio.com/cn/ReSpeaker_Mic_Array_v2.0/
树莓派3
该功能类似天猫精灵,即在设备播放过程中检测唤醒词用于打断或重定向任务。
即让智能设备在"说"的时候同时还可以"听" ,人类是有意识的,所以自己说的话和外界的声音很容易分辨,但是机器不行。
根据介绍,该设备中有一些算法 (DSP 算法,包括声学回声消除 (AEC),波束成形,去混响,噪声抑制和增益控制。)但是最有意思的是声源定位,这个很好玩。
该设备主要三个类型,贵一点的是集成开发环境、便宜点的是插在树莓派上使用的,但是gpio都被占用这个过分了。我用的是usb的,因为linux 免驱动,这个还是挺方便的。
该设备主要有两种固件,主要区别就是通道数不同,上手第一件事就是更新固件,因为6通道的版本功能强了不少。
通道 0 : ASR 处理音频,通道 1 : mic1 原始数据,通道 2 : mic2 原始数据,通道 3 : mic3 原始数据,通道 4 : mic4 原始数据,通道 5 : 合并播放
0通道就是我们需要的,该设备内置的算法会放大你说话的音量、降低背景音量,但是又不能完全去除背景音
接下来
git clone https://github.com/respeaker/usb_4_mic_array.git
cd usb_4_mic_array
python tuning.py -p
使用tuning.py可以设置设备内部参数具体如下:
#自适应回声抵消器更新抑制 0 自适应已启用 1 冻结自适应,仅限过滤器 'AECFREEZEONOFF': (18, 7, 'int', 1, 0, 'rw', 'Adaptive Echo Canceler updates inhibit.', '0 = Adaptation enabled', '1 = Freeze adaptation, filter only'), #AEC滤波器系数范数的极限 'AECNORM': (18, 19, 'float', 16, 0.25, 'rw', 'Limit on norm of AEC filter coefficients'), #AEC路径更改检测 0 false 1 true 'AECPATHCHANGE': (18, 25, 'int', 1, 0, 'ro', 'AEC Path Change Detection.', '0 = false (no path change detected)', '1 = true (path change detected)'), #当前RT60估计值(秒) 'RT60': (18, 26, 'float', 0.9, 0.25, 'ro', 'Current RT60 estimate in seconds'), #麦克风信号的高通滤波器 'HPFONOFF': (18, 27, 'int', 3, 0, 'rw', 'High-pass Filter on microphone signals.', '0 = OFF', '1 = ON - 70 Hz cut-off', '2 = ON - 125 Hz cut-off', '3 = ON - 180 Hz cut-off'), #RT60 AES估算 'RT60ONOFF': (18, 28, 'int', 1, 0, 'rw', 'RT60 Estimation for AES. 0 = OFF 1 = ON'), #AEC中信号检测的阈值 'AECSILENCELEVEL': (18, 30, 'float', 1, 1e-09, 'rw', 'Threshold for signal detection in AEC [-inf .. 0] dBov (Default: -80dBov = 10log10(1x10-8))'), #AEC远端静音检测状态 0检测信号 1 静音检测 'AECSILENCEMODE': (18, 31, 'int', 1, 0, 'ro', 'AEC far-end silence detection status. ', '0 = false (signal detected) ', '1 = true (silence detected)'), #自动增益控制 'AGCONOFF': (19, 0, 'int', 1, 0, 'rw', 'Automatic Gain Control. ', '0 = OFF ', '1 = ON'), #最大AGC增益因数 'AGCMAXGAIN': (19, 1, 'float', 1000, 1, 'rw', 'Maximum AGC gain factor. ', '[0 .. 60] dB (default 30dB = 20log10(31.6))'), #输出信号的目标功率电平 'AGCDESIREDLEVEL': (19, 2, 'float', 0.99, 1e-08, 'rw', 'Target power level of the output signal. ', '[−inf .. 0] dBov (default: −23dBov = 10log10(0.005))'), #当前AGC增益因数 'AGCGAIN': (19, 3, 'float', 1000, 1, 'rw', 'Current AGC gain factor. ', '[0 .. 60] dB (default: 0.0dB = 20log10(1.0))'), #上升/下降时间常数,以秒为单位。 'AGCTIME': (19, 4, 'float', 1, 0.1, 'rw', 'Ramps-up / down time-constant in seconds.'), #舒适性噪音插入 'CNIONOFF': (19, 5, 'int', 1, 0, 'rw', 'Comfort Noise Insertion.', '0 = OFF', '1 = ON'), #自适应波束形成器更新 'FREEZEONOFF': (19, 6, 'int', 1, 0, 'rw', 'Adaptive beamformer updates.', '0 = Adaptation enabled', '1 = Freeze adaptation, filter only'), #静止噪声抑制 'STATNOISEONOFF': (19, 8, 'int', 1, 0, 'rw', 'Stationary noise suppression.', '0 = OFF', '1 = ON'), #平稳噪声的过减因子。最小值。。最大衰减 'GAMMA_NS': (19, 9, 'float', 3, 0, 'rw', 'Over-subtraction factor of stationary noise. min .. max attenuation'), #固定噪声抑制增益下限 'MIN_NS': (19, 10, 'float', 1, 0, 'rw', 'Gain-floor for stationary noise suppression.', '[−inf .. 0] dB (default: −16dB = 20log10(0.15))'), #非平稳噪声抑制 'NONSTATNOISEONOFF': (19, 11, 'int', 1, 0, 'rw', 'Non-stationary noise suppression.', '0 = OFF', '1 = ON'), #非平稳噪声的过减因子。最小值。。最大衰减 'GAMMA_NN': (19, 12, 'float', 3, 0, 'rw', 'Over-subtraction factor of non- stationary noise. min .. max attenuation'), #非平稳噪声抑制的增益下限 'MIN_NN': (19, 13, 'float', 1, 0, 'rw', 'Gain-floor for non-stationary noise suppression.', '[−inf .. 0] dB (default: −10dB = 20log10(0.3))'), #回声抑制 'ECHOONOFF': (19, 14, 'int', 1, 0, 'rw', 'Echo suppression.', '0 = OFF', '1 = ON'), #回波的过减因子(直接分量和早期分量)。最小值。。最大衰减 'GAMMA_E': (19, 15, 'float', 3, 0, 'rw', 'Over-subtraction factor of echo (direct and early components). min .. max attenuation'), #回波(尾分量)的过减因子。最小值。。最大衰减 'GAMMA_ETAIL': (19, 16, 'float', 3, 0, 'rw', 'Over-subtraction factor of echo (tail components). min .. max attenuation'), #非线性回波的过减因子。最小值。。最大衰减 'GAMMA_ENL': (19, 17, 'float', 5, 0, 'rw', 'Over-subtraction factor of non-linear echo. min .. max attenuation'), #非线性回波衰减。 'NLATTENONOFF': (19, 18, 'int', 1, 0, 'rw', 'Non-Linear echo attenuation.', '0 = OFF', '1 = ON'), #非线性AEC训练模式。 'NLAEC_MODE': (19, 20, 'int', 2, 0, 'rw', 'Non-Linear AEC training mode.', '0 = OFF', '1 = ON - phase 1', '2 = ON - phase 2'), #语音检测状态 'SPEECHDETECTED': (19, 22, 'int', 1, 0, 'ro', 'Speech detection status.', '0 = false (no speech detected)', '1 = true (speech detected)'), #FSB更新决策 'FSBUPDATED': (19, 23, 'int', 1, 0, 'ro', 'FSB Update Decision.', '0 = false (FSB was not updated)', '1 = true (FSB was updated)'), #FSB路径变化检测 'FSBPATHCHANGE': (19, 24, 'int', 1, 0, 'ro', 'FSB Path Change Detection.', '0 = false (no path change detected)', '1 = true (path change detected)'), #瞬态回波抑制 'TRANSIENTONOFF': (19, 29, 'int', 1, 0, 'rw', 'Transient echo suppression.', '0 = OFF', '1 = ON'), #VAD语音活动状态 'VOICEACTIVITY': (19, 32, 'int', 1, 0, 'ro', 'VAD voice activity status.', '0 = false (no voice activity)', '1 = true (voice activity)'), #ASR的平稳噪声抑制 'STATNOISEONOFF_SR': (19, 33, 'int', 1, 0, 'rw', 'Stationary noise suppression for ASR.', '0 = OFF', '1 = ON'), #ASR的非平稳噪声抑制 'NONSTATNOISEONOFF_SR': (19, 34, 'int', 1, 0, 'rw', 'Non-stationary noise suppression for ASR.', '0 = OFF', '1 = ON'), #ASR平稳噪声的过减因子 'GAMMA_NS_SR': (19, 35, 'float', 3, 0, 'rw', 'Over-subtraction factor of stationary noise for ASR. ', '[0.0 .. 3.0] (default: 1.0)'), #ASR非平稳噪声的过减因子。 'GAMMA_NN_SR': (19, 36, 'float', 3, 0, 'rw', 'Over-subtraction factor of non-stationary noise for ASR. ', '[0.0 .. 3.0] (default: 1.1)'), # 'MIN_NS_SR': (19, 37, 'float', 1, 0, 'rw', 'Gain-floor for stationary noise suppression for ASR.', '[−inf .. 0] dB (default: −16dB = 20log10(0.15))'), #ASR的固定噪声抑制增益下限。 'MIN_NN_SR': (19, 38, 'float', 1, 0, 'rw', 'Gain-floor for non-stationary noise suppression for ASR.', '[−inf .. 0] dB (default: −10dB = 20log10(0.3))'), #设置语音活动检测的阈值。 'GAMMAVAD_SR': (19, 39, 'float', 1000, 0, 'rw', 'Set the threshold for voice activity detection.', '[−inf .. 60] dB (default: 3.5dB 20log10(1.5))'), # 'KEYWORDDETECT': (20, 0, 'int', 1, 0, 'ro', 'Keyword detected. Current value so needs polling.'), #方位角。当前值。方向取决于生成配置。 'DOAANGLE': (21, 0, 'int', 359, 0, 'ro', 'DOA angle. Current value. Orientation depends on build configuration.')
这些内部参数可以通过该指令来设置比如关闭自动增益 python tuning.py AGCONOFF 0
也可以使用代码读取其中的参数值
这段代码实际上读取的是VOICEACTIVITY这个参数值,该参数的阀值可以通过GAMMAVAD_SR来控制
需要注意的是这些个参数设置完了以后,重新启动即会回复为默认值。
声源定位
读取的是DOAANGLE 也就是最后一个参数。
如果遇到usb.core.USBError: [Errno 13] Access denied
try:https://blog.csdn.net/weixin_43928944/article/details/109742040
import pyaudio import wave import numpy as np RESPEAKER_RATE = 16000 RESPEAKER_CHANNELS = 6 # change base on firmwares, 1_channel_firmware.bin as 1 or 6_channels_firmware.bin as 6 RESPEAKER_WIDTH = 2 # run getDeviceInfo.py to get index RESPEAKER_INDEX = 0 # refer to input device id CHUNK = 1024 RECORD_SECONDS = 7 WAVE_OUTPUT_FILENAME = "output.wav" p = pyaudio.PyAudio() stream = p.open( rate=RESPEAKER_RATE, format=p.get_format_from_width(RESPEAKER_WIDTH), channels=RESPEAKER_CHANNELS, input=True, input_device_index=RESPEAKER_INDEX, ) print("* recording") frames = [] for i in range(0, int(RESPEAKER_RATE / CHUNK * RECORD_SECONDS)): data = stream.read(CHUNK) # extract channel 0 data from 6 channels, if you want to extract channel 1, please change to [1::6] a = np.frombuffer(data, dtype=np.int16)[0::6] frames.append(a.tostring()) print("* done recording") stream.stop_stream() stream.close() p.terminate() wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb') wf.setnchannels(1) print(p.get_sample_size(p.get_format_from_width(RESPEAKER_WIDTH))) wf.setsampwidth(p.get_sample_size(p.get_format_from_width(RESPEAKER_WIDTH))) wf.setframerate(RESPEAKER_RATE) wf.writeframes(b''.join(frames)) wf.close()
device id可以用以下代码查看
import pyaudio
p = pyaudio.PyAudio()
info = p.get_host_api_info_by_index(0)
numdevices = info.get('deviceCount')
for i in range(0, numdevices):
if (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0:
print("Input Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0, i).get('name'))
主要代码在voice-engine中
git clone https://github.com/voice-engine/voice-engine
由于ReSpeaker使用来大量的三方开源库,环境搭建起来超级麻烦,这个跟它的价格形成了鲜明的对比,显然有些low
在voice-engine你可以看到比如回声处理和降噪都是用现成的
降噪
看一下 voice_engine中的栗子声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/288687
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。