Workaround for Snips issue with latest Raspbian

Hi Everyone,

The Snips audio server is having some backend issues with portaudio on the latest Raspbian kernels 4.19. Here is a workaround for it for anybody experiencing issues with it!

To setup Snips with MATRIX devices, follow our Snips Hackster guide here with the following tweaks after the step where you run sam init on your PC:

On your RPi, in the /etc/snips.toml file, add the following line in the [snips-audio-server] section

Environment="PA_ALSA_PLUGHW=1"

image

On your RPi, in the /etc/asound.conf file, add the following line in the pcm.speaker section

rate 16000

image

Then Snips should work on your MATRIX device as desired!

Remember to restart the snips-audio-server by typing the following line into your PC’s terminal.

sam service restart snips-audio-server

Best,
Samreen

Hi Samreen,

I couldn’t get it to work so far. Here is what syslog says:

Jun 17 09:53:44 raspberrypi systemd[1]: Started Snips Audio Server.
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: INFO:snips_audio_server_cli: Starting audio server on mqtt for site default
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 923
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 923
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.front.0:CARD=0'
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM front
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround21
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround21
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround40.0:CARD=0'
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround40
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround41
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround50
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround51
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround71.0:CARD=0'
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround71
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM iec958
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM spdif
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM spdif
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
Jun 17 09:53:44 raspberrypi snips-audio-server[1160]: INFO:snips_audio_portaudio : Use input device: "default"
Jun 17 09:53:49 raspberrypi snips-audio-server[1160]: INFO:snips_broadcast_mqtt_server: Starting broadcasting audio on hermes as site "default"
Jun 17 09:53:49 raspberrypi snips-audio-server[1160]: ERROR:snips_audio_server         : an error occured: Can not read a stopped source
Jun 17 09:53:49 raspberrypi snips-audio-server[1160]:  -> caused by: Can not read a stopped source
Jun 17 09:53:49 raspberrypi systemd[1]: snips-audio-server.service: Main process exited, code=exited, status=1/FAILURE
Jun 17 09:53:49 raspberrypi systemd[1]: snips-audio-server.service: Unit entered failed state.
Jun 17 09:53:49 raspberrypi systemd[1]: snips-audio-server.service: Failed with result 'exit-code'.
Jun 17 09:53:54 raspberrypi systemd[1]: snips-audio-server.service: Service hold-off time over, scheduling restart.
Jun 17 09:53:54 raspberrypi systemd[1]: Stopped Snips Audio Server.

I installed the kernel-modules and configured Snips:

sam setup audio
Is it a Snips Makers Kit? No
Found 3 interfaces to record sound.
  Choose the one you want to use Karte 3: MATRIXIOSOUND [MATRIXIO-SOUND], Gerät 0: matrixio.mic.0 snd-soc-dummy-dai-0 []
Found 5 interfaces to output sound.
  Choose the one you want to use as your speaker Karte 2: Device [USB PnP Sound Device], Gerät 0: USB Audio [USB Audio]
✔ Installed /etc/asound.conf
Setting to volume to 90% if possible 
Restarting snips-audio-server service done 
i You can test your microphone & speaker with sam test microphone / speaker 

sam test microphone
i Plug in your microphone and turn on your speaker 
Stopping snips audio server 
✔ Say something in the microphone, then press a key to continue...
✔ Playing the recording
Relaunching snips-audio-server 
i Didn't hear anything? Check the recording level of your microphone and the volume of the speaker. 
i Alternatively you can run sam setup audio to setup your microphone 

This works as expected, I can hear my voice being played after the recording successfully.

Here’s asound.conf, note there is no pcm.speaker section:

pcm.!default {
    type asym
    playback.pcm {
        type plug
        slave.pcm "hw:2,0"
    }
    capture.pcm {
        type plug
        slave.pcm "hw:3,0"
    }

Any ideas on what is the problem?

Thanks!

Edit: Looks like its more a problem of snips not Matrix. When I start snips-audio-server manually and provide the microphone name, it works!

sudo snips-audio-server --mike "MATRIXIO-SOUND: - (hw:2,0)" -v

But when snips-audio-server is started by systemctl, it always tries to use “default” and fails. in snips.toml there is:

[snips-audio-server]
# frame = 256
# bind = "default@mqtt"
# mike = "Built-in Microphone"
# disable_playback = false
# disable_capture = false
mike = "MATRIXIO-SOUND: - (hw:2,0)"
Environment=“PA_ALSA_PLUGHW=1”

Edit: Solved! Have a look at my snips.toml where it says:

Environment=“PA_ALSA_PLUGHW=1”

Problem was I just copy&paste this line from your post above.

The quotation signs are not standard " but ”. This cannot be parsed and the whole config is broken. Replace them with “normal” ones and everything is fine.

1 Like

Awesome! So sorry about the quotation issue, turns out the editor in this forum does that unless I specify the line as a code block which I didn’t do, just fixed it! Glad you figured it out :smiley: