Matrix Voice & PyAudio

Hi :slight_smile:
I have successfully configured my Matrix Voice and it detects hotwords well. Thank you for good work ))

But I have some issue: I configured custom hotword because Snips dont support my language yet. So I did it and then I tried to write custom handler on mqtt Matrix Voice events using Python and PyAudio. Aaaand…I realized that there is some problems: PyAudio returns an error even when I’m trying to start your example script from here

My asound.conf and python traceback:

pcm.!default {
  type asym
  capture.pcm "mic"
  playback.pcm "speaker"

pcm.mic {
   type softvol
   slave {
     pcm "array"
   control {
     name "MicArray Master"
        card "MATRIXIOSOUND"

pcm.speaker {
  type plug
  slave {
    pcm "hw:0,0"
    rate 16000

pcm.array {
  type plug
  slave {
    pcm "hw:MATRIXIOSOUND"

Traceback (most recent call last):
  File "", line 13, in <module>
    stream =,
  File "/home/pi/smarthome/venv/lib/python3.8/site-packages/", line 750, in open
    stream = Stream(self, *args, **kwargs)
  File "/home/pi/smarthome/venv/lib/python3.8/site-packages/", line 441, in __init__
    self._stream =**arguments)
OSError: [Errno -9998] Invalid number of channels

Hope you can help me :slight_smile:

I figured out that problem was in blocking I/O by snips-audio-server. So if it’s started there is no way to access microphone input…
Is there some possibility to realize next scenario?

  1. snips-hotword detects my personal hotword and sends mqtt message (in topic hermes/hotword/friday/detected)
  2. snips-audio-server stops blocking microphone input for example for 5 seconds
  3. python script receive the mqtt message about hotword detection and tries to record audio with PyAudio and Matrix Microphones?
  4. after that snips-audio server takes microphone I/O control back

So, if Snips does not support your language, what good is it to use it?
And if you choose a language supported, why is there the need for a custom hotword? (Beside the fact that it’s cool)

I do not know what language you need, but you might consider Rhasspy:

At the beginning of project I was looking at Snowboy word detection because it’s the best solution for me, but then I understood that Matrix Voice has a bad support of Snowboy (or the other way around) and I started to think what can I do with

So now I’m looking for next workaround:

  1. Detect hotword with and send mqtt message
  2. Python script runs “os.system(‘sam service stop snips-audio-server’)” and takes control of the microphone
  3. Python script with SpeechRecognition library records the audio stream and sends it to Google TTS (but now I have problems in this step, supposetly with alsa library)
  4. Python script runs “os.system(‘sam service start snips-audio-service’)” and gives control of the microphone back to snips-audio-server

That workaround looks very bad and takes much time to turn off and then turn on snips-audio-server, but now it’s only one solution that I came to.

If you have working solution with Snowboy - you are welcome :slight_smile: But I think that there is some problems with sync of Matrix and Snowboy (or maybe I’m a noob).

Or maybe someone can help me with this or…maybe someone already streamed audio over mqtt?

Matrix Voice is a Mic Array, there is no such thing as “bad support of Snowboy”.

I think you really should check into Rhasspy

Yes, see my repo here: