Speaker Cancellation

Hi all,

Rhasspy + Buster + Respeaker 2 + speaker connected to Respeaker 2.

i’d like to play some audio through the speaker like a webradio mp3 stream for example. My problem is that if something comes out of speaker, Respseaker is completely deaf to voice commands.
It only works if i set playback to 20ish in alsamixer but of course it is not loud enough to listen to the radio.

This seems completely logical since the sound coming out of speaker is much closer than my voice.

Is there a way to cancel the stream going to speaker in ALSA?
To schematize, something like capture = capture - playback

I know Pulseaudio has some noise cancellation features but i’m not aware of this kind of cancellation and Pulseaudio gives me headaches.

For this you’ll need Acoustic Echo Cancellation (AEC).

The Respeaker Mic Array v2 do this natively using the XMOS chip. Though the playback audio quality is limited to 16khz.

Pulseaudio provides an AEC module but this requires more CPU resources and I was not able to get good results on a Raspnerry Pi (but it might be possible).

Otherwise there is a software from the guys at SeeedStudios that work with a custom ALSA pipe device they provide but I was not able to get it to work as good as the Respeaker builtin AEC.

Hope this helps.

1 Like

one word : amazing

i’ll try the ALSA plugin, thx

If you manage to get good results I’ll be interested :+1::blush:

With the Respeaker Mic Array V2 I’m able to detect the wakeword from across the room (5m+) with music playing pretty loud (the Respeaker/raspberry/speakers case design is paramount).

When the wakeword is detected you’ll have to lower/pause the music playback to get good ASR results.

I think i’m far to getting it right, i’ve installed ec et ALSA plugins but

in one terminal i launch
./ec -i 'plughw:CARD=seeed2micvoicec,DEV=0' -o 'plughw:CARD=seeed2micvoicec,DEV=0' -d 200

and in another one i launch
arecord -q -r 16000 -f S16_LE -c 1 -t raw -D 'fifo' test.wav

i stop it but at playback, i need to double the rate to get normal sound speed, Rhasspy won’t like that
aplay -q -r 32000 -f S16 -c 1 -t raw test.wav

furthermore i cannot play anything through mplayer as soon as ./ec is launched since it uses directly the hardware card plughw:CARD=seeed2micvoicec,DEV=0 :frowning:

feeling dumb…

ALSA can be quite frustrating sometimes…

I think you need to use a pipe device for playback as well.

From the README of ec

# terminal #1, run ec
./ec -h
./ec -i plughw:1 -o plughw:1 -s

# terminal #2, play 16k fs, 16 bits, 1 channel raw audio
cat 16k_s16le_mono_audio.raw > /tmp/ec.input

# terminal #3, record
cat /tmp/ec.output > 16k_s16le_stereo_audio.raw

You may have to create a dmix device in front of the pipe device to allow multiple process to access the same device.

here is my asound.conf

pcm.!default {
    type asym
    playback.pcm "playback"
    capture.pcm "capture"
}

pcm.playback {
    type plug
    slave.pcm "dmixed"
}

pcm.capture {
    type plug
    slave.pcm "array"
}

pcm.dmixed {
    type dmix
    slave.pcm "hw:seeed2micvoicec"
    ipc_key 555555
}

pcm.array {
    type dsnoop
    slave {
        pcm "hw:seeed2micvoicec"
        channels 2
    }
    ipc_key 666666
}

pcm.fifo {
    type fifo
    file "/tmp/ec.input"
    infile "/tmp/ec.output"
    rate 16000
    format S16_LE
}

i tried to add a couple of PCMs such as

pcm.mplayer {
    type plug
    slave.pcm "dmixed"
}

or

pcm.mplayer {
    type dmix
    slave.pcm "hw:seeed2micvoicec"
    ipc_key 444444
}

but i must admit : i don’t understand what i’m doing :rofl:

if anyone has a working asound.conf…

Have you tried this?

I had trouble getting this to work for multiple playbacks at the same time (voice, music, etc) since dmix devices only accept a « hardware » device as slave. And the pipe is not considered « hardware » by ALSA. If you only want to play audio from a single mplayer then it might work. Otherwise you need a software mixer like Pulseaudio.

Using pulseaudio was easier to setup but prepare for high CPU resource usage (with a Rpi 4 it might be ok though). I was not able to get convincing results using Pulseaudio but I might have incorrectly configured it at the time.

That is why I chose the Respeaker Mic Array v2. It works flawlessly and do not consume resources. It’s expensive though :grimacing:

Respeaker Mic Array v2 has built-in AEC? No need for extra software or alsa config ?
If yes i’ll go for that straight away, thx

EDIT : just to be curious, why not choose ReSpeaker Core v2.0 directly ?

The Respeaker Core does not have AEC built in.

Curious: What’s the difference in the Respeaker Mic Array v2 and the ReSpeaker 6-Mic Circular Array kit for Raspberry Pi?

I actually got it working but if it works is another question :slight_smile:

Anyway will share as maybe you can tell me if it makes a difference load isn’t bad though.
My main problem was when I stopped recording ec would stop.
I got past that by using a loopback device sudo modprobe snd-aloop

So firstly my /etc/asound.conf

 pcm.!default {
    type asym
    playback.pcm "eci"
    capture.pcm "plughw:CARD=Loopback,DEV=1"
}


pcm.eci {
    type plug
    slave {
        format S16_LE
        rate 16000
        channels 1
        pcm {
            type file
            slave.pcm null
            file "/tmp/ec.input"
            format "raw"
        }
    }
}

pcm.eco {
    type plug
    slave.pcm {
        type fifo
        infile "/tmp/ec.output"
        rate 16000
        format S16_LE
        channels 2
    }
}

pcm.cap {
 type plug
 slave {
   pcm "plughw:CARD=CameraB409241,DEV=0"
   channels 4
   }
 route_policy sum
}

start ec with
./ec -i 'cap' -o 'plughw:CARD=ALSA,DEV=0' &
then redirect the mic to the loopback
arecord -D eco -q -r 16000 -f S16_LE -c 2 | aplay -D plughw:CARD=Loopback,DEV=0 &

The big question is does it actually work as yeah in the cli I can see aec switching on & off on play.
But does it make a difference?

@rolyan_trauts AEC is essential is you plan on playing music or radio streams through your assistant and you want it to respond during playback. I was not able to make the EC software work correctly so congrats :wink:

@fishertimj The difference is that the Respeaker Mic Array v2.0 have all the audio processing algos (NS, BF, AEC, etc.) directly on the integrated XMOS chip (no CPU required) whereas the 6-Mic does not.

Seeed provides a software (closed sources) on their custom version of Raspbian.

I cannot vouch for this software performance but I’m very satisfied with the Mic Array v2.0.

My assistant can ear me from more than 5 meters away even while playing loud music (2x3W). The loudspeaker placement and case design are paramount though.

Hope this helps

Yeah the Forrest Rhasspy can be a problem as you scream “Stop!”

On raspbian libspeexdsp is an older version than alsa-plugins requires to compile.
You get the speexlib but the dsp with ec doesn’t compile.
The speexdsp alsa-plugins are missing on raspbian or you can jump to ArchLinux Arm or
compile http://downloads.us.xiph.org/releases/speex/speexdsp-1.2.0.tar.gz
Grab the Alsa-plugins 1.8.1 (from mem on raspbian) recompile and you will get alsa speexdsp
so you can do things like the following and define in asound.conf

pcm.!default {
    type asym
    playback.pcm "plughw:CARD=ALSA,DEV=0"
    capture.pcm  "cap"
}

pcm.array {
 type hw
 card 1
}

pcm.cap {
 type plug
 slave {
   pcm "array"
   channels 4
   }
 route_policy sum
}

pcm.echo {
 type speex
 slave.pcm "cap"
 echo yes
 frames 256
 filter_length 1600
 denoise false
}

pcm.agc {
 type speex
 slave.pcm "echo"
 agc 1
 denoise yes
 dereverb yes
}

But still making a big mistake as if you read the speex manual clock drift across seperate cards will stop speexdsp from working. You need an all-in-one soundcard that has playback & capture and no async like I have.

Its BS that you can not do software EC but quite likely the software we have available isn’t implemented correctly as software EC has been done.
How well it works and load it produces is another matter, but yeah for one reason or another especially on the Pi it seems the software we have doesn’t work.

Pulseaudio with webtrc aec & speex dsp, seem to of added drift compensation that I am not sure if it works on Arm embedded.
They seemed to of fudged some things due to ‘incorrect latency’ reporting https://gitlab.freedesktop.org/pulseaudio/webrtc-audio-processing/-/blob/master/webrtc/modules/audio_processing/echo_cancellation_impl.cc#L63
I am not sure if the Pi fits any of the latency profiles they have provided.

// Measured delays [ms]
// Device                Chrome  GTP
// MacBook Air           10
// MacBook Retina        10      100
// MacPro                30?
//
// Win7 Desktop          70      80?
// Win7 T430s            110
// Win8 T420s            70
//
// Daisy                 50
// Pixel (w/ preproc?)           240
// Pixel (w/o preproc?)  110     110

// The extended filter mode gives us the flexibility to ignore the system's
// reported delays. We do this for platforms which we believe provide results
// which are incompatible with the AEC's expectations. Based on measurements
// (some provided above) we set a conservative (i.e. lower than measured)
// fixed delay.
//
// WEBRTC_UNTRUSTED_DELAY will only have an impact when |extended_filter_mode|
// is enabled. See the note along with |DelayCorrection| in
// echo_cancellation_impl.h for more details on the mode.
//
// Justification:
// Chromium/Mac: Here, the true latency is so low (~10-20 ms), that it plays
// havoc with the AEC's buffering. To avoid this, we set a fixed delay of 20 ms
// and then compensate by rewinding by 10 ms (in wideband) through
// kDelayDiffOffsetSamples. This trick does not seem to work for larger rewind
// values, but fortunately this is sufficient.
//
// Chromium/Linux(ChromeOS): The values we get on this platform don't correspond
// well to reality. The variance doesn't match the AEC's buffer changes, and the
// bulk values tend to be too low. However, the range across different hardware
// appears to be too large to choose a single value.
//
// GTP/Linux(ChromeOS): TBD, but for the moment we will trust the values.
#if defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_MAC)
#define WEBRTC_UNTRUSTED_DELAY
#endif

Pulseaudio is a bit of a stinker to setup in a docker container anyway and the advantage of docker outweighs pulseaudio use, but once again the software might not work on arm embedded.
The $75 mic array alone that is near as damn the cost of the full size Amazon or Google complete units makes Pi based versions extremely expensive equivalent private AIs.
Software should work as has and does but your right the software on the Raspbian doesn’t seem to.

Probably SoCs like the Rockchip RK3308 & Allwinner R328 might surprisingly come to the Pis aid and act as satelite mic/speakers to a centralised Pi as with embedded dsp/codec they are extremely low cost.
Software should work and unfortunately the cost to benefit of Pi system with hardware EC for many doesnt justify benefit.

I quite like the idea of a centralised Pi with satelites as the far field claims of the array mics with singular prominant noise sources doesn’t work well.
In industrial environs of loud dispersed noise where the actor is a predominant signal then they work well.
Have a TV or HiFI in between you and AI that is the predominant source, beamforming wonders or not when it comes to recognition then good luck.

Multiple cheap satelites makes sense and also allow you to create multi-channel audio, but if the Allwinner R329 with built in NLP is as low cost as the R328 we might still be on debian but the Raspberry connection might not make cost sense.

Software can work for EC as the criteria you need for EC doesn’t mean its crystal clear recording quality it just needs to be adequate to cork/duck playing media.
But probably means someone will have to fix or hack what we have into something that is fit for purpose as yeah it doesn’t seem to work with the Pi.

I am still exploring some cheaper options of the respeaker 2mic and the linear 4 mic that does have hardware loopback with speex-alsa.
Still waiting for deliveries due to current situation so just don’t know.

1 Like

I ran out of links due to my noob status but https://github.com/OAID all looks interesting for embedded irrespective of SoC.
http://www.tengine.org.cn/

Due to links still thinking either the rk3308 or r328 could make a great https://rhasspy.github.io/rhasspy-voltron/tutorials.html#server-with-satellites.

Still waiting for my https://wiki.radxa.com/RockpiS $13.99 but it might be painfull with a very new dts and debian image and looking like I have to figure the mic circuit out myself.
I know its called Rhasspy but the framework is so great an flexible that these might make a really great option.

I read some good reviews of the Respeaker 2 mic hat regarding sensitivity and far field capture. If ALSA AEC can be achieved using the loopback of the hat (or maybe using ALSA loopback plugin?) it will be a huge progress for vocal assistant :blush:

Really looking forward to your feedback :+1:

@fastjack how are you performing to play music over rhasspy and he is still listening for the wakeword? What Software are you using? I’ve been trying to play radio over mopidy and keep rhasspy to listen to the wakeword. Yet mopidy tells me that the resource is busy when I Start the radio stream. A busy resource makes sense to me. Thats why I wondering how you’re perforimg this task.

@fastjack

Yeah the respeaker or clone 2mic is a great option due to cost and if EC could be made to a level where VAD could kick in then maybe something could be workable.
VAD is in Speex and AEC is in SpeexDsp but its a maybe.

I will let you know but been waiting for some time for delivery https://www.ebay.co.uk/itm/Blesiya-ReSpeaker-2-Mic-Pi-HAT-V1-0-Expansion-Board-I2C-For-Raspberry-Pi/253876990739
But the master/satelite mode of rhasspy gets really cost effective with the Rockchip/Allwinner as the are just the right combination on silicon and not much use for anything else than satelite mic/speakers.
But the Pi3A+ and the above £10 mic/soundcard aint that bad a price.

@Bozor

pcm.!default {
    type plug
    slave.pcm "dmix"
}

You prob just need to add another line to your asound.conf and use a dmix pcm that multiple applications can use rather than a sole PCM or device.
Its “dsnoop” for mics “dmix” for outputs just do a google.

Also I have a ps3eye but with the driver problems even though it has a great array I think its a really bad device to use as it can cause all sorts of confusion with alsa-util failures and for a couple of $ more a 2 mic even has a little amp built in with some leds.
So yeah if EC can be made to work its definately a top pick and also even without EC, but that is another problem.
I have seen these on sale in China and have my fingers crossed at a similar price they will turn up on ebay or aliexpress.
http://bbs.16rd.com/shop_product-1-381.html
But that might be Yaun not Yen :slight_smile:

But supposedly similar as these https://detail.tmall.com/item.htm?id=569134471494
Is supposedly a R328 so fingers crossed wither way.

Any idea why this might not work within a Docker container? I can play and record from multiple applications at the same time outside of Docker (which indicates to me that my dmix and dsnoop config is working), but then when I try to play back a file from the host and from within the Rhasspy container at the same time, I get an error from aplay:

root@1530daa229ed:/usr/lib/rhasspy-voltron# aplay etc/wav/beep_hi.wav 
ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
aplay: main:828: audio open error: Device or resource busy

Is the Docker container is trying to grab the hardware device and create an entirely new dmix plugin instance within the container instead of using the existing one outside of the container?

I’ve tried linking my /etc/asoundrc.conf into the container, making /dev/snd/ available in the container, and even setting the container to privileged without any success.

This is on a Pi Zero so I’d rather not run pulseaudio and hog more CPU…

Any advice would be appreciated! Thanks!

Ooof if /dev/snd is avail then I thought that would be it.

Must be docker if running out but not in the container and pulseaudio with dbus and everything is even worse for docker implementation.

I know alsa from Mycroft experience but never run in a container.
I am a Rhasspy noob and just trying the new https://github.com/rhasspy/rhasspy-voltron which is just python virt-env
So have no idea don’t even know what you can run on a zero with rhasspy yet.

My advice would be to install in a virt-env rather than docker as prob not eloquent but as a noob its prob a fix.
Doubt you are running much else on a zero and also don’t know how much of rhasspy will run on a zero.

Unless its something as simple as the docker run needs --group-add audio aswell ? dunno guessing.
But apols as a bit stumped as thought that would just work.

[EDIT] apols
Doh you are creating a file to the asound.conf internal docker file? As it will not see /etc/asound.conf or .asoundrc from the host and not have or at least just be defaults
Also if you write changes it will not be persistant unless you add an external in the run.

I should of mentioned this doh! apols

-v /etc/asound.conf:/etc/asound.conf:ro

To the docker run

If not stumped as not really used the docker version and still very much a fresh rhasspy noob
The persistance and what is in the container can be mighty confusing at times

This is what I did, as I mentioned in my first post when I said that I tried linking my asoundrc.conf into the container. The container uses the host’s config successfully.

ALSA does take a bit to get your head wrapped around it all, but I feel like I’ve got a good grasp on it at this point - at least on the host directly. It’s the Docker game I’m still trying to figure out :slight_smile:

Thanks for the ideas! I’ll keep poking around.

Yeah as apols as same, thought that would just work.
Maybe its just a matter of https://rhasspy.readthedocs.io/en/latest/installation/#virtual-environment as really don’t know.
aplay --verbose see if it gives a clue, someone on here will know as sure this must be a common thing.

I’m sure if I ran Rhasspy through venv, I wouldn’t be having the issue… It’s something with Docker for sure.

No difference in the output with aplay -v in the container or out of it. I just get the error message inside the container whenever something is already playing out of it.

Yeah not really sure how to get more debug from alsa as its tricky if the logs and verbose output don’t give a clue.
Maybe alsa-info would show something but doubt it.
I would post elsewhere as the title of this thread is prob stopping replies.
Or Venv as presume on a zero being in a container is of little benefit.
Maybe just needs a unique ipc_key to host such as ipc_key 555555 and maybe create a asound.conf in $HOME as a dumb conatiner file or something so they can have different keys.
But dunno that is a straw clutch.

@fastjack

1st card to turn up is the 4 mic linear 4 Pi.

So not using loopback and running ec rather than ec_hw

The ec load seems very low on a Pi4 no OC

Now strangely because I have the 4 mic linear I haven’t been able to run ec_hw yet as not really sure which channel is the loopback.
But will try but the 4 mic linear seems great and actually not bad for £25 but the linear mic strip suits prob a retangle ‘radio’ shape box due to length.

I am pretty sure I can add some extra filters forgot the music term but that will filter out the low volume and that should reduce even further.

Speex & EC doesn’t totally remove echo and really needs the same sound card as clock drift kills its function.
But on a soundcard and presuming the 2mic will be the same its likely effective EC can be used to give a mic signal fit for purpose.

Now what I have to do is figure out how to install the drivers with rt-prempt kernel and see if that gives any improvement.
I ran with default EC settings so should also give that a play and think my pi4 is about 50ms latency so used that.
But I would say that this will run on a Pi3a+ dunno about the zero though.

I am using https://github.com/voice-engine/ec not sure what the speex alsa-plugins actually do?
Still got it set up via alsa with the ec asound.conf
Whats the term for a musical filter that removes the low volume portion of a wav?
But prob a few things I can still do to improve further.

1 Like

Sorry I did not read whole topic, but I can confirm, that Respeaker Mic Array v2 (USB) work very well with AEC (so MIC listen while audio is being played via same card). I reflashed firmware to 48kHz 1 mic channel. The only problem was to get Respeaker card working both output for Respeaker in Docker and Snapcast on host. I did solve it with help of others here on the forum.

Yeah the $70 Respeaker Mic Array v2 damn well ought to have hardware DSP :slight_smile:

You can do it with software with $10 2 mic Pi soundcards, been on a bit of a crusade to get it working.
I found that you have to have playback/capture on the same cards as since I got a 4mic linear for Pi software AEC works quite well.
The idea is satellite speaker/mics with with Pi4/Respeaker V2 USB starts to get a tad expensive.
But you can Pi3A+/2mic4Pi AEC away quite nicely for $35 and as a disclaimer haven’t tried the Pi3A+ but the load is so little on the Pi4 that I am presuming its yes.
I should get my skates on and check that.

There is a Master/Satellite form of Rhasspy that has a number of advantages and is pretty cool, but costs can quickly add up.
There is also the Software AEC of pulseaudio but again pulseaudio can be a docker pain and its adding more bloat to low end satellites that are little more than streaming speakers with mic arrays.

I think its of more interest for those who want to run home cloud AI without big data services.
But localising and distributing voice capture and creating what is essentially a wide array microphone has natural physics on its side rather than technology.

PS if anyone is trying the software.


Is slightly wrong edit ec.c so the frame size is a power of 2 and your FFT filter will be much better (128, 256 or 512) prob.
The line int frame_size = config.rate * 10 / 1000; // 10 ms even for someone like me is easy to change, then make.
The above line is likely to make primes not good for FFT.
[Pi3] with a quick test seems very much like the Pi4

Did you notice audio playback quality issue (like strange « shh ») with the 48Khz firmware?

Isn’t 16khz if you enable AEC, but that is my foggy memory but seem to remember thinking Oh so just wideband audio.

Just to update older thread, there is 48kHz firmware for Respeaker Mic Array v2 available. So AEC is now also available for 48kHz playback/recording.

Thanks. I know of it and tested it a few months back to no avail. AEC is pretty inexistant and audio playback quality suffers from strange saturation issues.

Seed has stated on their forum that the playback quality / AEC issue can not be solved because of the limited capabilities of the XMOS chip.

@litinoveweedle Hi :wave:. Can you confirm that the Respeaker 48KHz 1 channel firmware have a working AEC? Did you notice audio quality issues? Thanks :blush:

@fastjack On the topic of EC and hardware.
Got another Syba USB and again seems to be fake with a c-media mono mic chipset than the stereo via envy.

Also 2x I2S mics and a cheap china hdmi2hdmi+audio seems to work well.

Hello, sorry for late reply. The sound with 48kHz is little bit better than 16kHz, but is is far from perfect, there are some strange artifacts. AEC seems to be working but is far from perfect, especially when playing loud music.

I did checked all available MICs arrays, but all seems to be based on same chip (xmos XVF-3000), with same 16kHz limitation. I can only hope for some new MIC array with xmos XVF-3500 to arrive soon. :-o

@litinoveweedle

Could you try and help this guy out a Mic wise the Anker Anker PowerConf seems to be an amazing piece of kit.

For some reason aplay -Dplughw:1 -r16000 -f S16_LE file_example_WAV_10MG.wav works perfectly but playback from Rhasspby is cutting at the start and I am unsure why.

But might be of interest as they are a pretty new product and if aplay -Dplughw:1 -r16000 -f S16_LE file_example_WAV_10MG.wav works fine from the cli then I can not see it being the hardware.

Only thing I haven’t done is suggest creating an asound.conf defining sample rates and channels maybe summing them.

Sort of hard work remote and blind, I might take the plunge and buy one.

I’m using a ReSpeaker 4 Mic Array with a raspberry pi 3b+ and cannot run ec with “./ec -i plughw:CARD=seeed4micvoicec,DEV=0 -o plughw:CARD=seeed4micvoicec,DEV=0 -d 200”

It just says
cannot open audio device plughw:CARD=seeed4micvoicec,DEV=0 (No such file or directory)

Anyone have a respaeker 4 mic and got this working?

My arecord -L:
null
Discard all samples (playback) or generate zero samples (capture)
jack
JACK Audio Connection Kit
pulse
PulseAudio Sound Server
eci
eco
default
Playback/recording through the PulseAudio sound server
usbstream:CARD=b1
bcm2835 HDMI 1
USB Stream Output
usbstream:CARD=Headphones
bcm2835 Headphones
USB Stream Output
sysdefault:CARD=seeed4micvoicec
seeed-4mic-voicecard, bcm2835-i2s-ac10x-codec0 ac10x-codec.1-003b-0
Default Audio Device
dmix:CARD=seeed4micvoicec,DEV=0
seeed-4mic-voicecard, bcm2835-i2s-ac10x-codec0 ac10x-codec.1-003b-0
Direct sample mixing device
dsnoop:CARD=seeed4micvoicec,DEV=0
seeed-4mic-voicecard, bcm2835-i2s-ac10x-codec0 ac10x-codec.1-003b-0
Direct sample snooping device
hw:CARD=seeed4micvoicec,DEV=0
seeed-4mic-voicecard, bcm2835-i2s-ac10x-codec0 ac10x-codec.1-003b-0
Direct hardware device without any conversions
plughw:CARD=seeed4micvoicec,DEV=0
seeed-4mic-voicecard, bcm2835-i2s-ac10x-codec0 ac10x-codec.1-003b-0
Hardware device with all software conversions
usbstream:CARD=seeed4micvoicec
seeed-4mic-voicecard
USB Stream Output

Dunno try aplay -l and see if you can get it to work with the index number instead plughw:2 or whatever it will be

This is my aplay -l:
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 1: b1 [bcm2835 HDMI 1], device 0: bcm2835 HDMI 1 [bcm2835 HDMI 1]
Subdevices: 4/4
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
card 2: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 H eadphones]
Subdevices: 4/4
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3

I might be wrong, but doesn’t this only list playback devices, not mics? The respaeker isn’t there anyway

You are missing card 0 from your cut and paste but presume thats the loopback.
But that looks like the respeaker is not installed or installed but not found.

PS is this docker or just host install?

If Im not mistaken, you are using the normal 4mic Respeaker Board that doenst have an audio out. So you will not find it in your aplay.
In this case, your sound output is probably routed through the 3.5mm from the PI itself.

1 Like

Yeah, the respeaker is not listed with aplay -l. Does that mean I cannot use the echo cancelling program on my mic?
It’s Raspbian installed with the Rhasspy .deb, so I guess host?

Yeah it uses the clock sync on in and out to match the AEC, AEC works only with cards or USB that both play and record.

I sort of hate that 4 mic I have one in a box and doh it was late at night as always going on about how they are whole load of nothing with a pixel ring.
Nice Pixel ring but otherwise pretty useless.

Have a word with @JGKK as think he now also about a USB dongle or the https://www.raspberrypi.org/products/iqaudio-codec-zero/ looks pretty amazing if it ever gets stocked.

Without high speed DSP beamformingn, algs multiple omnidirectional mics are useless as even when summed they can create 1st order filters and even can be even detrimental than just pointless.
The are just more of the same so you have a mc and a pixel ring and the 4 mic is just one of those products they make cause they can because they sell even if they know they are pretty pointless.

Alright, thank you so much for explaining.
I think I’ll buy a ReSpeaker Mic Array v2.0 instead as it actually has EC and noise suppression built-in. Hopefully it will filter out loud music and background noise well.

A unidirectional electret mic has an element of natural AEC as well as directionality that with the addition of AEC probably with the hardware we have makes for the best MIC for a builder unless your going to spend a lot of $ on a DSP high end mic.

A USB cheap sound card is a few $ and with a MAX9814 mic module provides a double dose of AGC that can give really good far results on a budget.
I will see if I can get @JGKK to comment as always chanting this mantra but maybe he will give a honest review on a recent test he has done.

It would be awesome if a MAX9814 microphone with the EC program could be almost as good as a ReSpeaker Mic Array v2.0. Would love to try it out sometime to see.
I found this guide which seems very helpful for beginners.

The Respeaker Mic Array is not that great from other reviews, I have a Anker Powerconf which is a Xmos chip above the Respeaker and its OK but like all it fails when noise=near & voice=far.
noise=near & voice=far happens far often than you would expect in a domestic situation such as hifi, radio and TV to even the washing machine and is very dependent on the placement of a single device.
AEC can cope with the noise it plays but 3rd party noise has no input and is a problem for all.

Its better to have multiple devices and use the stream with the best KW hit confidence as with correct placement it is likely to have more chance of getting nearer to voice=near & noise=far.

Just a shame rhasspy doesn’t support this or multiple instances of KWS mics in a single device as the unidirectional can face out at different angles.

https://www.scan.co.uk/products/enermax-ap001e-dreambass-usb-soundcard-plus-earphones-genie-with-integrated-80-hz-plus6-db-bass-boos
Is prob the best usb sound card on the market for price as S243LE cards at 48kHz tend to be prosumer studio prices but £7 from scan.
Its stereo and you can phantom power electret mics with it.
So you can add another if rhasspy does ever do miltiple kws instance.

Mono mic cards I will give examples from raspberry shops but you can find them cheaper on ebay.

Or the CM108 module seems to be popular.

unidirectional electrets with good sensitivity need some sourcing but

Which is me as other you end up buying x25 from aliexpress as those seemed to have really good sensitivity.

Max9814 the ones with the onboard ldo regulator seem to be better for SNR

They end up about the same price as a 2mic or approx half the 2mic raspberry codec zero HAT, but generally I think they are better.

https://speechbrain.github.io/ is a speech toolkit that comes with beamforming algs its currently going through a stage beta / bug testing and should go public soon.
I have not looked enough to test but prob will as if it will run then multi-mic does become valid.

1 Like

Hey folks,

Did anyone try AEC on Respeaker Core v2? They supply librespeaker with DSP algorithms from 3rd-party provider Alango. Specifically, there’s a VepAecBeamformingNode which should do AEC automatically (according to docs). But I’m wondering how? It’s not really clear how to supply an output audio stream to this library to be able to correctly apply AEC. When I tried to play a random music file while active listening, it didn’t seem like AEC works at all. As it’s a C++ library, I guess music should be played from code and somehow plugged into librespeaker node chain. Note that Alango delegates tech support to Seeed Studio and Seeed Studio doesn’t reply for a couple of years neither on GitHub nor on their forum / email.

P.S. I already have a code that successfully does WWD, NS, AGC, DOA and BF. Not perfect, but good enough to use this board for common smart home tasks. The only important thing left is the acoustic echo canceller. Any thoughts/suggestions would be greatly appreciated.

I think the respeaker blurb if not is very close to snakeoil as yeah the Alango EC wasn’t free and you just have an API for it.
https://github.com/voice-engine/ec works pretty well in fact it seems the only EC that works on a PI level hardware as the pulseaudio webrtcec only works on really low levels and then fails.

Its based on SpeexDSP you have to have audio in/out on the same card and a bit of a hack with piping through a loopback adapter but the Respeaker Core does that not have hardware one?
If not you can just modprobe a kernel one.
On raspi os speexdsp & speex are missing from asound2-plugins as for some reason its an old version.
But instructions here.

I did some simple one-liner helper scripts here

Its echo attenuation but works well enough that barge-in should work.

PS that Respeaker Core v2 is some where between a Zero & 3 in oomph?
If your doing something yourself have a look at Googles state of the art KWS for tensorflow-lite
https://github.com/StuartIanNaylor/google-kws runs about 70% on a Zero so should work well on a Core2 but is heavily optimized for 64bit and a Pi3 will likely greatly outperform running TFL on Aarch64

Without beamforming algs the mic array on that board is a whole lot of pointless even when you sum its likely to be detrimental as the will form 1st order high pass filters based on the distance apart.
You prob should use a single channel.
I don’t think its got the Ooomf to run ODAS.

1 Like

Thanks for the extensive reply!

According to specs, Respeaker Core v2 has 8-channels ADCs for 6-microphone array and 2 loopbacks (hardware loopback).

The main problem I see with an external EC is the actual integration to my code. librespeaker already does beamforming, wake word detection, noise suppression, automatic gain control, etc for me. I can’t simply run an external service that does AEC separately. It should be tightly coupled to the existing chain of operations.

As far as I understood, the above EC writes the output to the file. And librespeaker works with mics directly. Well, technically it can read a 8-channels wav-file as an input. So theoretically, if the above EC had top processing priority, it could do AEC and save the output to wav, which could be used as an input for librespeaker in the next step. However, I’m not really sure about the real-time performance of such an approach, as it would lead to constant I/O operations against SD Card. Ideally, this EC code should behave as a middleware w/o saving intermediate results to the file. But I’m not sure if it’s even technically possible.

The files are not files they are really buffers in /tmp that it uses.

Also not sure you do have beamforming working unless you have got ODAS working, maybe it was just me but from memory the API is there but it misses the Alango libs so can not work. (no libs for the API to link to)
If you check the forum link of Software EC it creates a virtual source based on the file fifo where what is played is subtracted from the mic input.

So you use that as your mic input so when installed EC works in the background and for config you just select that PCM.

1 Like

@sskorol I had a quick stalk :slight_smile: and you are defo no dummy and maybe your the man to implement this?

1 Like

Also not sure you do have beamforming working unless you have got ODAS working, maybe it was just me but from memory the API is there but it misses the Alango libs so can not work. (no libs for the API to link to)

I’m not using ODAS lib. And in terms of Alango libs: I talked to Alango support and they told me that Seeed Studio is their partner and built a custom framework around Alango VEP package. As far as I understood, librespeaker is exactly what they call “framework”. And yes, it’s not bundled and applied by default on Respeaker Core v2. You have to install librespeaker-dev deb package which includes corresponding headers so that you can use them in your C++ code the way it’s described in docs.

In general, I like how KWS, NS and AGC works (based on VepAecBeamformingNode). Beamforming seems to be working where we have a single source input (it can be partially tracked by their DOA manager, which is a part of Alango as well). It gives a quite accurate direction of a detected wake word. On the other hand, it doesn’t seem to correctly focus on a required direction when we have an additional input source e.g. TV. Ideally, it should eliminate other sources when the wake word is detected and its direction is well-known.

P.S. I asked Alango for the required details, but they provide tech support only for commercial projects. Moreover, as Seeed Studio has built its own framework, it’s not the responsibility of Alango anymore. Unfortunately, it seems like a dead-end, assuming the fact that Seeed Studio representatives don’t reply at all.

You got further than me as the dead-end of info halted my course.

This VepAecBeamformingNode provides beamforming, AEC, NR and DOA algorithms from Alango.

I could get no info on the algs from Alango, but reading again it does say provides.
I am not sure if there is more info now on the respeaker site or it makes more sense now my knowledge has evolved.

I haven’t got a sbc to test and think my 4 mic should work but its gathering dust somewhere.
If you are sure you got beamforming working maybe :-
int ref_channel_index should be mono audio out channel that aec uses as for beamforming a ref channel is not needed.

If you enable bool enable_wav_log does that give you a log to work on?

1 Like

Thanks for the link. Will check it later. However, according to installation section, it seems more like a server-side software. At least when I see keywords like CUDA, it wasn’t meant to be designed for hardware like Respeaker. I tried Vosk ASR toolkit which is based on Kaldi. It does MFCC and other stuff as well. But I wasn’t impressed with CPU performance at all. At least on RPi hardware it works very slow. So I’ve chosen NVIDIA Jetson boards that allow building and using all those math/ML stuff with GPU support.

Yes, it saves wav-files for each channel. However, I haven’t yet tried it in the context of AEC processing. Will enable log, play some audio and check what’s going on there maybe later today. Thanks for the tips.

With the respeaker librespeaker I think you are trailblazing as far as I know you are the 1st to get the beamforming working.
You might find https://speechbrain.github.io/ of interest if on Jetson as pytorch audio seems vendor locked to either intel mkl or nvidia ones.
It does do various beamforming dunno about load.

1 Like

In case anyone is interested, i have speaker cancelation running on PulseAudio. I have this on a plain Ubuntu, no Docker, but should be the same if you run any Linux PulseAudio host.

Add this:

load-module module-echo-cancel use_master_format=true aec_method=webrtc rate=48000 source_name=echoCancel_source sin
set-default-source echoCancel_source
set-default-sink echoCancel_sink

to your pulse config (usually /etc/pulse/config.pa - you may have another in ~/.config/pulse). This sets AEC as default on boot. use_master_format=true preserves the speaker setup (e.g. multi channel).
Additionally, you need to ensure that rhasspy starts after pulse. In case you use systemd, use this in your service config file:

After=syslog.target network.target pulseaudio.service

In case you have a multi channel speaker setup (>2), you may also want to disable stereo upmix for stereo sources not beeing mirrored to the rear speakers. Usually, this is done via

enable-remixing = no

in your pulse audio daemon.conf (e.g. /etc/pulse/daemon.conf), but this will not work if your mic is multi channel (like PS3 Eye). In this case, you can use:

remixing-use-all-sink-channels = no

2 Likes

Problem with PulseAudio Webrtc_AEC is that it will setup but when you test the output it fails at even moderate levels of echo on a Pi.
I am not sure if a Pi3/4 has the clock speed or maybe data length as you can install it but the results are very poor.
It actually does cancellation rather than attenuation but when the echo level hits a threshold (quite low) it totally fails and all echo enters the stream.

If you have an echo/home type arrangement with speaker/mic in close proximity last time I ran it, it was near useless as the threshold was hit most of the time and it did nothing.
Maybe we have had an update in raspbian now that pulse audio is the default on the desktop.
I never really got to the source of the problem but in the pulse audio code it assigned latency by platform type of Desktop, Mac & Android or something as it was quite a while ago, but latencies where hardcoded by platform.
I wondered if it was a typical thing when Arm is running full linux and gets lumped in as a X86 desktop.

Easiest way is to test and post a raw input vs resultant AEC result as do you have an example of it working?
Might of been fixed but think we are still on the same version that we we over a year ago.

I have to admit, this setup is running on a Celeron Processor N4100, not a PI. For validation, i simply checked the difference between the mic activation levels (raw and AEC) and it is pretty clearly working… Wake word false positive rate after 4-6h series/movie watching was zero. (at least, not due to speaker sound :wink: )
If you are interested in examples from the x86, i can provide some.

On a sidenote: i didnt test speedx, which is supposedly comsuning less resources.

No as your input is welcome but found it to work on x86 seemed to do with my desktop.
Its just on a Pi where it does actually work but on only really low levels of ‘echo’ in the mic stream.
AEC only cancels what you play it doesn’t handle 3rd party noise, presume you watched on device?

Yes, you are right - i supressed a known source (watched on same device). The docs are not 100% clear on that, but it seems like the pulse audio module is also supposed to do noise cancelation. However, i wouldnt assume it to be able to supress unkown, load, voice sources. I don’t see how such a module would be able to differentiate between “human” and “tv” voice.
Maybe microphone beamforming is an option for you?

Yeah the noise cancellation is a bit pants apart from newer techs like nvidia voice as they leave audio artifacts that can reduce recognition.
The Arch docs are prob best for PA AEC.

I have been playing with the new TFL state-of-art KWS models and with a custom dataset of my voice the crrn-state model does an amazing job of just picking up my voice, just haven’t got enough words of mine in ‘unknown’