Matrix Voice: How to use matrix_lite with Python

Hi all,

after struggling with Matrix Core…
…I switched to Matrix Lite:
https://github.com/matrix-io/matrix-lite-py

I finished the installation procedure successfully.

Than I thought I can use the matrix_lite module in my python-action-files (used in my snips-app).
But this seems not to work.

Can you tell me or provide a link to a description where to implement the LED control function and how to trigger?

Thx and hope to read you soon!

Cheers

Hi @toby2018,

Are you calling your python code through the action tab in the snips console?

Most snips skills use python 2.7, but since python 2 will be deprecated soon, MATRIX Lite python only supports python 3. This may be what’s causing your issue.

If this is the case, you could simply listen to the Hermes messages via MQTT. Basically, you should be able to do an equivalent of what we do in assistant.js, but in Python. You would need to install paho-mqtt to read the snips messages, and respond with MATRIX Lite.

Then, you would install the snips assistant, run the python program you wrote, and should be able to get your desired responses.

Best,
Samreen

Hi @Samreen,

This is basically my action code, in Python 3:

#!/usr/bin/env python3

-- coding: utf-8 --

from hermes_python.hermes import Hermes

from matrix_lite import led


def action_wrapper(hermes, intent_message):
# Sets each LED to blue
# led.set(‘blue’) # color name

current_session_id = intent_message.session_id
hermes.publish_end_session(current_session_id, result_sentence)

# Turns off each LED
# led.set('black')  # color name

if name == “main”:
with Hermes(“localhost:1883”) as h:
h.subscribe_intent(“toby2018:getHowAreYou”, action_wrapper).start()

When uncommenting the import of matrix_lite the script does not react anymore.

Cheers Toby

Hey @toby2018!

I haven’t played around with the snips action code environment, but you might have some luck by installing matrix-lite-py globally.

sudo python3 -m pip install matrix-lite

If you’re still having trouble, can you verify:

Let us know if you’re still experiencing any issues. I can try testing this week to debug.

1 Like

Hi @Carlos,

Got it :slight_smile:
Everloop is working and LED is shining :blush:

Cheers…

2 Likes

Great to hear! I’ll update our documentation to use that installation instead.