Mycroft on Respeaker Core V2

Mycroft on Respeaker Core V2

Respeaker Core V2 (short: RC2) is a Single Board Computer with a technical specification similar to a Raspberry Pi3 - but with some more goodies:

  • builtin microphone array (6 mics) which supports
    • beamforming
    • noise suppression
    • echo cancellation
  • led pixel ring
  • user button
  • 4GB eMMC memory (so you don’t need a SD-card)
  • JST2-connector to connect a small loudspeaker

Overall the RC2 is a nice package to run Mycroft on…

Preparation

RC2 runs with Debian 9 (Stretch). Seeedstudio (the vendor of RC2) provides prebuilt images where drivers for the onboard sound card are already installed and configured.

First you must decide if you want to install the OS to the onboard eMMC memory or run it directly from SD-card.
Go to fangcloud and navigate to respeakerv2 > debian > YYYYMMDD.
For the eMMC option download the
respeaker-debian-9-iot-flasher-********-4gb.img.xz.
In case you prefer to run the OS from the SD-card you should download the respeaker-debian-9-iot-sd-********-4gb.img.xz.

Burn the downloaded image to an SD-card (e.g. using Etcher), then insert the SD-card in the RC2 card slot and power it on. When you have choosen the eMMC option it will take approximately 10 minutes to copy the data from SD-card to the onboard memory.

Configure WiFi

After the OS install you must connect the RC2 to a PC via USB cable using the micro USB port labeled “OTG”. Then run a serial console program using 115200 baud rate, 8Bits, Parity None, Stop Bits 1, Flow Control None.
Login with user “respeaker” and password “respeaker”. Then run the setup with sudo nmtui and enter your WiFi credentials.

More detailed instructions for preparation and WiFi setup can be found here

Mycroft setup

OS update

First you should update the operating system:

sudo apt update
sudo apt upgrade

Respeaker daemon

Next step is installing respeakerd which provides the software stack for beamforming, noise reduction and echo cancellation:

curl https://raw.githubusercontent.com/respeaker/respeakerd/master/scripts/install_all.sh|bash

Next edit /etc/respeaker/respeakerd.conf and change the line starting with mode to mode = pulse

Then edit /etc/pulse/default.pa and add following lines

load-module module-pipe-source source_name="respeakerd_output" format=s16le rate=16000 channels=1
set-default-source respeakerd_output

Finally start the respeaker daemon with sudo systemctl start respeakerd

You may want to perform an audio test by:

parecord --channels=8 --rate=16000 --format=s16le hello2.wav
paplay hello2.wav

Mycroft install

Now your RC2 is ready to install Mycroft. This is done by a git-install:

cd ~/
git clone https://github.com/MycroftAI/mycroft-core.git
cd mycroft-core
bash dev_setup.sh

During the setup you will be asked some questions, here is a rundown of my recommended answers:

  • Y)es, run on the stable ‘master’ branch
  • Y)es, automatically check for updates
  • N - skip Mimic build
  • Y - Adding Mycroft commands to your PATH

NOTE: When you have chosen to install the OS on the eMMC you have only 4GB available! Whenever running dev_setup.sh you should consider adding the option -sm to skip the install of Mimic as this will several hundreds MB additional memory…

After setup is finished you are ready to run Mycroft for the first time:

cd ~/mycroft-core
./start-mycroft.sh debug

Respeaker-IO-Skill

I have written a Mycroft-skill that supports the LED pixel ring and the user button. You can install the skill by

mycroft-msm install https://github.com/domcross/respeaker-io-skill.git

Advanced options

Here are some advanced options, inspired by the blog of Mycroft community user @j1nx

Use RAM-disk for IPC

Mycroft uses a message bus over which the different Mycroft services communicate - the so called “inter process communication” (IPC). This will result in a lot of read and write operation to the file system which can “wear out” your SD-card. To avoid that you can redirect the IPC to a RAM-Disk:

sudo mkdir /ramdisk

The edit /etc/fstab and add following line to the end:

tmpfs /ramdisk tmpfs rw,nodev,nosuid,size=20M 0 0

sudo mkdir /etc/mycroft

Edit (new) file `/etc/mycroft/mycroft.conf:

{
  "ipc_path": "/ramdisk/mycroft/ipc/"
}

Automatically start Mycroft while booting

Until now you have to manually start Mycroft each time you have rebooted your RC2. Here is how to automatically run by using systemd:

Edit (new) file /etc/systemd/system/mycroft.service:

[Unit]
Description=Mycroft personal AI
After=respeakerd.service

[Service]
User=respeaker
WorkingDirectory=/home/respeaker/mycroft-core
ExecStart=/home/respeaker/mycroft-core/start-mycroft.sh all
ExecStop=/home/respeaker/mycroft-core/stop-mycroft.sh
Type=forking
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

User respeaker must be member of groups pulse and pulse-access, otherwise sound output will no work:

sudo usermod -a -G pulse respeaker
sudo usermod -a -G pulse-access respeaker

Then enable the “Mycroft service” by

sudo systemctl enable mycroft.service

8 Likes

That looks like a nice piece of hardware!

Thanks for sharing your learnings and writing that skill to make it even easier too

1 Like

Great write-up and thanks for the “ping”!

Forked your skill, because somewhere in the near future I want to do the same for their 4-Mic Pi HAT.

Anyhow, will put that device on my todo/to buy list. Looks very interesting. How are the;

  • beamforming
  • noise suppression
  • echo cancellation

Performing?

I did only tests in a “laboratory stage” so far where the RC2 is sitting “naked” on my workdesk:

When running the respeaker-daemon in debug mode I can see that different directional information is shown when I change my position while speaking, so the beamforming/direction-of-arrival algorithm does work.

In another test I triggered a skill that plays MP3-stream and Mycroft still recognized the wake-word and triggered the desired skill/intent - the echo cancellation does work as well. My Mark-1 and my PiCroft with Google-AIY-hat in the same scenario (playing music stream in with similar loudness) stayed silent as they couldn’t hear me any more…

I am now looking for a case where the RC2 fits into, then I will perform real word tests…

By the way: the ReSpeaker Pro Case is for the Core V1 only - the RC2 has larger dimensions and does not fit into it (found it out the hard way…)

This sounds like an important development, because I’m finding the picroft distribution to be essentially useless for music without echo cancellation. Have you found any drawbacks compared to the Raspberry pi?

I did not perform actual benchmark testing but my impression is that overall performance of the RC2 is similar to the Raspberry Pi 3B. Drawbacks: as stated above there is no case for the RC2 and it does not have extensive GPIO support as the Raspberry has.

If you want echo-cancellation with Mycroft on a Raspberry Pi you might want to look at Respeaker 6mic circular array or the 4mic linear array - both have hardware loopback channel which enables the echo-cancellation (all other Respeaker mic hats for Raspberry do NOT have hw-loopback and therefore no echo-cancellation).

Has anyone actually had success with a raspberry pi hearing them through the respeaker while music is playing? That would be reason to buy the respeaker, but frankly I don’t care much about the lights.

For that you need echo-cancellation (EC). Looking at Respeaker devices only the 4-mic linear array and the 6-mic array can do EC (the 2-mic and 4-mic circular can’t do EC as they have no hardware loopback).

Using one of these, follow the instructions for installation of the seeedvoicecard-driver from the Wiki, then install respeakerd (you probably need to change some configuration settings depending on your mic-array model).

1 Like

@Dominik
Hey can you tell me what is about this 4-mic speaker:
http://wiki.seeedstudio.com/ReSpeaker_4_Mic_Array_for_Raspberry_Pi/

Does ist support echo-cancellation, beamforming or noise suppression?

Hi @suisat,
The “circular” 4-mic array does have DOA (Direction of Arrival - beamforming), VAD (Voice Activity Detection) and KWS (Keyword Spotting or Keyword Search) but does NOT have echo-cancellation due to hardware limitations (no loopback channel).

The “linear” 4-mic array has other hardware including loopback channel which enables echo-cancellation, but lacks the LED pixel ring.

In case you want echo-cancellation and LED pixel ring you should look at the “circular” 6-mic array.

@Dominik

Hi, I just want t follow up on this post from April. I have a Rasp Pi 4, and a Seeed 6 MIC array. I have installed the respeakerd. Is this all I need to do? Do I need to configure something on the Mycroft side to enable the echo suppression?

Thanks and Regards,

Stephen

Hi @Stephen_O_Sullivan

No configuration on Mycroft side necessary. The setup script for respeakerd installs all required components, including librespeaker (which does the actual echo cancellation) and configures pulseaudio.

http://wiki.seeedstudio.com/ReSpeaker_6-Mic_Circular_Array_kit_for_Raspberry_Pi/#librespeaker-aduio-process

Just ordered one of these. Glad I saw this post as I was going to purchase the ReSpeaker mic array v2.0 and use it on top of an RPi. Knowing the core works as an integrated unit is great news.

Seeed provide drawings and (I think) the files to 3D print a stand. Which is comprised of multiple layers connected by standoffs, which shapes what looks like a chamber for a down firing speaker.

http://wiki.seeedstudio.com/ReSpeaker_Core_v2.0/#resources

Hi All,
@Dominik, many thanks for the reply. I installed it, but my Mic does not seem to be able to record since I installed the respeakerd library. Even using arecord. I have no doubt I have made a mistake somewhere, I just need to go through everything with a fine tooth comb and find it.

I’ll check back here if I find something.

I found the source of my issue. It was the `https://github.com/domcross/respeaker-io-skill.git skill. Uninstall and everything works fine.

Looks like I have to add another topic on my to-do list :laughing:

I can not rule out that that the respeaker-io skill causes the respeakerd service to malfunction as I simply mixed some code examples from the respeaker wiki pages for that…

Hi @Dominik,

no big deal. Your code was for the Respeaker Core V2, I have a Respeaker 6-mic array. I found this: ReSpeaker 4-Mic Array HAT Mycroft A.I. Skill (ReSpeaker 4-Mic Array HAT Mycroft A.I. Skill) and the developer says he built it on your work. So maybe her can point you in the direction of the problem? This works on the Rasp Pi 4.

Regards,

Stephen

1 Like

Hi @Dominik, I’ve received my V2 unit and followed these instructions. The microphone works brilliantly, very clear recordings.

I have no audio output of any kind though. Not from Mycroft, which uses pulse, or from Raspotify, which uses ALSA.

aplay -l shows a single output device, the seeed card. But a pacmd list-sinks shows only a null device. Or rather, it complains that no daemon is running. After starting pulse manually and using the pacmd list-sinks command again, it shows the null.

The seeed wiki seems to indicate that the seeed voicecard audio output ALSA device actually redirects the audio to pulse. This would explain why a service that doesn’t use pulse and rather relies on ALSA directly, would still fail to produce any sound.

What pulse sink devices do you see on yours? Did you have to take any extra steps to get audio output working?

I am using the iot image from seeed, which is cli only. I’m considering reflashing the lxqt image and starting again. I had hoped to build for rapid start times and low memory demand though.

Don’t know if this helps but here are some outputs

    $ aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: seeed8micvoicec [seeed-8mic-voicecard], device 1: 100b0000.i2s1-rk3228-hifi rk3228-hifi-1 []
      Subdevices: 1/1
      Subdevice #0: subdevice #0
$ pactl list sinks
Sink #0
	State: SUSPENDED
	Name: auto_null
	Description: Dummy Output
	Driver: module-null-sink.c
	Sample Specification: float32le 2ch 48000Hz
	Channel Map: front-left,front-right
	Owner Module: 13
	Mute: no
	Volume: front-left: 23593 /  36% / -26.62 dB,   front-right: 23593 /  36% / -26.62 dB
	        balance 0.00
	Base Volume: 65536 / 100% / 0.00 dB
	Monitor Source: auto_null.monitor
	Latency: 0 usec, configured 0 usec
	Flags: DECIBEL_VOLUME LATENCY 
	Properties:
		device.description = "Dummy Output"
		device.class = "abstract"
		device.icon_name = "audio-card"
	Formats:
		pcm
$ pactl list source
Source #0
	State: SUSPENDED
	Name: auto_null.monitor
	Description: Monitor of Dummy Output
	Driver: module-null-sink.c
	Sample Specification: float32le 2ch 48000Hz
	Channel Map: front-left,front-right
	Owner Module: 13
	Mute: no
	Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
	        balance 0.00
	Base Volume: 65536 / 100% / 0.00 dB
	Monitor of Sink: auto_null
	Latency: 0 usec, configured 0 usec
	Flags: DECIBEL_VOLUME LATENCY 
	Properties:
		device.description = "Monitor of Dummy Output"
		device.class = "monitor"
		device.icon_name = "audio-input-microphone"
	Formats:
		pcm

Source #1
	State: SUSPENDED
	Name: respeakerd_output
	Description: Unix FIFO source /tmp/music.input
	Driver: module-pipe-source.c
	Sample Specification: s16le 1ch 16000Hz
	Channel Map: mono
	Owner Module: 22
	Mute: no
	Volume: mono: 65536 / 100% / 0.00 dB
	        balance 0.00
	Base Volume: 65536 / 100% / 0.00 dB
	Monitor of Sink: n/a
	Latency: 0 usec, configured 0 usec
	Flags: DECIBEL_VOLUME LATENCY 
	Properties:
		device.string = "/tmp/music.input"
		device.description = "Unix FIFO source /tmp/music.input"
		device.icon_name = "audio-input-microphone"
	Formats:
		pcm

When I check status of respeakerd by sudo systemctl status respeakerd I get a strange result:

   Loaded: loaded (/lib/systemd/system/respeakerd.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2020-03-05 20:23:11 CET; 4min 53s ago
  Process: 1902 ExecStart=/usr/bin/respeakerd_safe (code=exited, status=1/FAILURE)
 Main PID: 1902 (code=exited, status=1/FAILURE)

Nevertheless Mycroft works (wakeword and intents).

I am using the “iot” image as well. The reference to the “lxqt” in my entrance posting is actually a typo (unfortunately I am not able to edit it anymore).

Thanks for taking the time to reply. Unfortunately that output is exactly what I was seeing, so no clues there.

I did get pulse audio running in system mode, which provided some better looking output from pactl list sinks, i could see what looked like a proper audio device. Alas, still no sound output!

I’ve actually reflashed the lxqt image, but haven’t had much time for the project since then.