Spkr won't play (or stop) music


#1

Hi,
I think I’ve set everything up correctly - mike and speakers are ok, I’m logged into spotify via mopidy and I have an assistant in the correct place. I can play music using the iris web interface. Still can’t get any positive response from spkr.

I have only set up the software on a Rpi3 without the lights etc round the top.

Last logs after asking to play some music;
Aug 23 11:26:34 spkr docker[449]: [10:26:34.155287] #033[32mINFO #033[0m:#033[1m queries_hermes #033[0m: Idle
Aug 23 11:26:34 spkr docker[449]: [10:26:34.176920] #033[32mINFO #033[0m:#033[1m snips_dialogue::dialogue#033[0m: State: WaitingIntent, incoming Message: Nlu(Int entParsed)
Aug 23 11:26:34 spkr docker[449]: [10:26:34.177216] #033[32mINFO #033[0m:#033[1m snips_dialogue::services#033[0m: publish Intent(“PlayMusicCreativeWork”)
Aug 23 11:26:34 spkr docker[449]: [10:26:34.177325] #033[32mINFO #033[0m:#033[1m snips_dialogue::dialogue#033[0m: Current State: Idle
Aug 23 11:26:34 spkr docker[449]: [10:26:34.177413] #033[32mINFO #033[0m:#033[1m snips_dialogue::services#033[0m: publish Asr(ToggleOff)
Aug 23 11:26:34 spkr docker[449]: [10:26:34.177468] #033[32mINFO #033[0m:#033[1m snips_dialogue::services#033[0m: publish Hotword(ToggleOn)
Aug 23 11:26:34 spkr docker[449]: [10:26:34.263228] #033[32mINFO #033[0m:#033[1m snips_analytics_hermes#033[0m: Cleanup
Aug 23 11:26:34 spkr docker[449]: [10:26:34.263389] #033[32mINFO #033[0m:#033[1m snips_analytics_hermes#033[0m: Idle
Aug 23 11:26:45 spkr docker[449]: [10:26:45.181683] #033[32mINFO #033[0m:#033[1m snips_dialogue::services#033[0m: publish Asr(ToggleOff)
Aug 23 11:26:45 spkr docker[449]: [10:26:45.181854] #033[32mINFO #033[0m:#033[1m snips_dialogue::services#033[0m: publish Hotword(ToggleOn)

Any help appreciated - looks like a great project if I can overcome this.


#2

I notice the line and the intent changes depending on what I say to Snips, so I’m guessing that it’s understanding what I’m asking it to do.

How do I translate that into an action that it actually does?


#3

Hi @steve !

Thanks for your interest in spkr !
At Snips, we are moving fast, and we are not afraid to break things ! A result is that as for now the spkr image is a bit outdated, and doesn’t work with the latest docker image of snips.

Don’t worry though, we are updating the spkr image and we should have one ready by next week that works out of the box !

For now, what you can do is head over to the home-python folder. From here, edit the relay.py file, with the following body :

from __future__ import absolute_import, unicode_literals

import json
import time

import paho.mqtt.client as mqtt

from datetime import datetime
from music import Music
from state_service import StateService, State


DEBUG = False

MQTT_HOST = 'spkr.local' if DEBUG else 'localhost'
BASE_URL = 'http://spkr.local:6680' if DEBUG else 'localhost:6680'

MQTT_CHANNEL_SEARCH_MUSIC = 'hermes/intent/PlayMusicCreativeWork'
MQTT_CHANNEL_PLAY_PLAYLIST = 'hermes/intent/PlayMusicPlaylist'
MQTT_CHANNEL_PLAY = 'hermes/intent/ResumeMusicCreativeWork'
MQTT_CHANNEL_STOP = 'hermes/intent/StopMusicCreativeWork'
MQTT_CHANNEL_PAUSE = 'hermes/intent/SuspendMusicCreativeWork'
MQTT_CHANNEL_NEXT_TRACK = 'hermes/intent/NextIntent'
MQTT_CHANNEL_PREVIOUS_TRACK = 'hermes/intent/PreviousIntent'
MQTT_CHANNEL_STT_SPEECH = 'hermes/Speech'
MQTT_CHANNEL_STT_HOTWORD = 'hermes/asr/toggleOn'

PRINT_LOGS = True
current_volume = 0
VOLUME_WHILE_LISTENING = 40
MIN_VOLUME = 25


def process_stt_feedback(music, event):
    if event == 'SPEECH_ON':
        global current_volume
        current_volume = music.get_volume()
        music.set_volume(VOLUME_WHILE_LISTENING)
        return 'Speech ON'

    elif event == 'SPEECH_OFF':
        global current_volume
        music.set_volume(max(MIN_VOLUME, current_volume))
        return 'Speech OFF'

    return 'Speech in unrecognized state'


def process_sdk_msg(music, sdk_msg, state):
    slots = json.loads(sdk_msg)["slots"]
    type = json.loads(sdk_msg)['intent']['intentName']


    if type is None:
        return 'no type found'

    elif 'PreviousIntent' == type:
        music.previous()
        state.set_state(State.found_high)
        return 'Previous track'
    
    elif 'NextIntent' == type:
        music.next()
        state.set_state(State.found_high)
        return 'Next track'

    elif 'ResumeMusicCreativeWork' == type:
        music.play()
        state.set_state(State.found_high)
        return 'Play music'

    elif 'SuspendMusicCreativeWork' == type:
        music.pause()
        state.set_state(State.found_high)
        return 'Pause music'

    elif 'StopMusicCreativeWork' == type:
        music.pause()
        state.set_state(State.found_high)
        return 'Stop music'

    elif 'PlayMusicPlaylist' == type:
        playlist = None

        for slot in slots:
            if ('slotName') in slot:
                slot_name = slot['slotName']
                if 'musicPlaylistName' == slot_name:
                    playlist = slot['value']

        if playlist is not None and 0 != len(playlist):
            state.set_state(State.found_high)
            music.set_playlist(playlist)
            music.play_first()
            return 'Playing playlist'

    elif 'PlayMusicCreativeWork' == type:
        genre = None
        track_album_artist = None
        mood = None

        for slot in slots:
            if 'slotName' in slot:
                slot_name = slot['slotName']
                if 'musicCreativeWorkGenre' == slot_name:
                    genre = slot['value']
                if 'musicCreativeWorkArtistName' == slot_name:
                    track_album_artist = slot['value']['value']
                if 'musicCreativeWorkName' == slot_name:
                    track_album_artist = slot['value']['value']

        if genre is not None and 0 != len(genre):
            state.set_state(State.found_high)
            music.set_search(music.search_genre(genre))
            music.shuffle()
            music.play_first()
            return 'playing genre "' + genre + '"'

        elif track_album_artist is not None and 0 != len(track_album_artist):
            if "Nickelback" in track_album_artist:
                state.set_state(State.error)
                time.sleep(3)
                state.set_state(State.error)
                return None
            else:
                state.set_state(State.found_high)
                music.set_search(
                    music.search_any(track_album_artist)
                )
                music.play_first()
            return 'playing songs related to "' + track_album_artist + '"'
        elif mood is not None and 0 != len(mood):
            print("can't handle mood")
            state.set_state(State.error)
        else:
            state.set_state(State.error)
            return 'invalid query ' + json.dumps(query)
    else:
        state.set_state(State.error)
        return 'unkown type ' + type


class Relay():
    def __init__(self):
        self.mqttc = mqtt.Client()
        self.music = Music(BASE_URL)
        self.state = StateService()

        self.mqttc.on_message = self.on_message
        self.mqttc.on_connect = self.on_connect
        self.mqttc.on_publish = self.on_publish
        self.mqttc.on_subscribe = self.on_subscribe

        self.mqttc.on_log = self.on_log

    def on_connect(self, mqttc, obj, flags, rc):
        print('Connected to host')
        self.mqttc.subscribe(MQTT_CHANNEL_SEARCH_MUSIC, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_PLAY_PLAYLIST, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_PLAY, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_STOP, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_PAUSE, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_NEXT_TRACK, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_PREVIOUS_TRACK, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_STT_SPEECH, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_STT_HOTWORD, 0)

    def on_message(self, mqttc, obj, msg):
        print('Received message on' + ' ' + msg.topic + ' ' + msg.payload)
        print(msg.topic)
        start = datetime.now()
        response = None
        if msg.topic == '/hermes/speaker/state':
            response = self.state.process_state_msg(msg.payload)
        
        elif msg.topic == MQTT_CHANNEL_STT_HOTWORD:
            response = process_stt_feedback(self.music, "SPEECH_OFF")
            self.state.set_state(State.found_low)
            # response = self.state.process_state_msg(State.found_low)
        
        elif msg.topic == MQTT_CHANNEL_STT_SPEECH:
            response = process_stt_feedback(self.music, "SPEECH_ON")
            self.state.set_state(State.loading)

        else:
            try:
                response = process_sdk_msg(self.music, msg.payload, self.state)
            except:
                pass

            if response is None:
                self.mqttc.publish("/hermes/mopidy/error", payload="error")
            else:
                self.mqttc.publish("/hermes/mopidy/success", payload="success")

        end = datetime.now()
        print('Duration: {0}'.format(end - start))
        # response = process_mqtt_msg(self.music, msg)
        # response = process_sdk_msg(self.music, msg.payload)
        print(response)

    def on_publish(self, mqttc, obj, mid):
        print('mid: ' + str(mid))

    def on_subscribe(self, mqttc, obj, mid, granted_qos):
        print('Subscribed: ' + str(mid))

    def on_log(self, mqttc, obj, level, string):
        if PRINT_LOGS:
            print(string)
        return None

    def run(self):
        self.mqttc.connect(MQTT_HOST, 9898, 60)
        self.mqttc.loop_forever()

From there, just reboot your Raspberry Pi, and you should be good to go !

Cheers,

Anthony !


#4

Hi Anthony,

Thanks for your help, still didn’t respond though. Tried on my original setup and then freshly installed one.

Any other ideas welcome - else I will wait for new image next week.


#5

Hey @steve,
I updated the code snippet in my previous post to disable the debug mode, and handle a new case for the music playback. It works fine on my side. Can you try it out ?

If it doesn’t work, can you give me the output of the following commands please ?

sudo systemctl status mopidy.service -l
sudo systemctl status spkr.snips.service -l
sudo systemctl status spkr.python.service -l

Cheers :v:t5:!


#6

Hi Anthony, thanks again, but still no luck I’m afraid

sudo systemctl status mopidy.service -l
● mopidy.service - Mopidy music server
Loaded: loaded (/lib/systemd/system/mopidy.service; enabled)
Active: active (running) since Fri 2017-08-25 09:56:18 UTC; 4min 38s ago
Process: 748 ExecStartPre=/bin/chown mopidy:audio /var/cache/mopidy (code=exited, status=0/SUCCESS)
Process: 729 ExecStartPre=/bin/mkdir -p /var/cache/mopidy (code=exited, status=0/SUCCESS)
Main PID: 758 (mopidy)
CGroup: /system.slice/mopidy.service
├─ 758 /usr/bin/python /usr/bin/mopidy --config /usr/share/mopidy/conf.d:/etc/mopidy/mopidy.conf
└─1547 /usr/bin/pulseaudio --start --log-target=syslog

Aug 25 09:56:24 spkr mopidy[758]: INFO Logged in to Spotify in offline mode
Aug 25 09:56:25 spkr mopidy[758]: INFO Logged in to Spotify in online mode
Aug 25 09:56:43 spkr mopidy[758]: INFO Starting Mopidy frontends: IrisFrontend, MpdFrontend, HttpFrontend
Aug 25 09:56:43 spkr mopidy[758]: INFO Starting Iris 2.13.14
Aug 25 09:56:43 spkr mopidy[758]: INFO MPD server running at [::ffff:0.0.0.0]:6600
Aug 25 09:56:43 spkr mopidy[758]: INFO Starting GLib mainloop
Aug 25 09:56:43 spkr mopidy[758]: INFO HTTP server running at [::ffff:0.0.0.0]:6680
Aug 25 09:58:02 spkr pulseaudio[1547]: [pulseaudio] server-lookup.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Aug 25 09:58:02 spkr pulseaudio[1547]: [pulseaudio] main.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Aug 25 09:58:02 spkr mopidy[758]: WARNING GStreamer warning: gst-stream-error-quark: No volume control found (3)

sudo systemctl status spkr.snips.service -l
● spkr.snips.service - snips NLU Service
Loaded: loaded (/lib/systemd/system/spkr.snips.service; enabled)
Active: active (running) since Fri 2017-08-25 09:56:07 UTC; 5min ago
Main PID: 448 (docker)
CGroup: /system.slice/spkr.snips.service
└─448 /usr/bin/docker run -t --rm --name snips -p 9898:1883 -v /etc/asound.conf:/root/.asoundrc -v /opt/snips/config:/opt/snips/config --privileged -v /dev/snd:/dev/snd snipsdocker/platform

Aug 25 10:01:03 spkr docker[448]: [10:01:03.294053] INFO :snips_dialogue::services: publish Hotword(ToggleOn)
Aug 25 10:01:23 spkr docker[448]: [10:01:23.293929] INFO :snips_dialogue::dialogue: Timeout is reached. Going to Idle mode
Aug 25 10:01:23 spkr docker[448]: [10:01:23.294086] INFO :snips_dialogue::services: publish Asr(ToggleOff)
Aug 25 10:01:23 spkr docker[448]: [10:01:23.294217] INFO :snips_dialogue::services: publish Hotword(ToggleOn)
Aug 25 10:01:43 spkr docker[448]: [10:01:43.294040] INFO :snips_dialogue::dialogue: Timeout is reached. Going to Idle mode
Aug 25 10:01:43 spkr docker[448]: [10:01:43.294195] INFO :snips_dialogue::services: publish Asr(ToggleOff)
Aug 25 10:01:43 spkr docker[448]: [10:01:43.294283] INFO :snips_dialogue::services: publish Hotword(ToggleOn)
Aug 25 10:02:03 spkr docker[448]: [10:02:03.294144] INFO :snips_dialogue::dialogue: Timeout is reached. Going to Idle mode
Aug 25 10:02:03 spkr docker[448]: [10:02:03.294301] INFO :snips_dialogue::services: publish Asr(ToggleOff)
Aug 25 10:02:03 spkr docker[448]: [10:02:03.294389] INFO :snips_dialogue::services: publish Hotword(ToggleOn)

sudo systemctl status spkr.python.service -l
● spkr.python.service - snips Python Service
Loaded: loaded (/lib/systemd/system/spkr.python.service; enabled)
Active: failed (Result: exit-code) since Fri 2017-08-25 09:56:10 UTC; 6min ago
Process: 449 ExecStart=/usr/bin/python /home/pi/home-python/home (code=exited, status=1/FAILURE)
Main PID: 449 (code=exited, status=1/FAILURE)

Aug 25 09:56:10 spkr python[449]: File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 686, in connect
Aug 25 09:56:10 spkr python[449]: return self.reconnect()
Aug 25 09:56:10 spkr python[449]: File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 808, in reconnect
Aug 25 09:56:10 spkr python[449]: sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
Aug 25 09:56:10 spkr python[449]: File “/usr/lib/python2.7/socket.py”, line 571, in create_connection
Aug 25 09:56:10 spkr python[449]: raise err
Aug 25 09:56:10 spkr python[449]: socket.error: [Errno 111] Connection refused
Aug 25 09:56:10 spkr python[449]: sounds/wake1.wav: No such file or directory
Aug 25 09:56:10 spkr systemd[1]: spkr.python.service: main process exited, code=exited, status=1/FAILURE
Aug 25 09:56:10 spkr systemd[1]: Unit spkr.python.service entered failed state.

hope this helps

Steve


#7

Thanks a lot @steve !

I think your problem stems from the spkr.python.service. It starts too early. We will push a fix for this in the new image for spkr.

I suggest you reboot your Raspberry Pi and follow these steps :

  1. Boot your Raspberry, and wait for a whole minute for everything to start
  2. Stop the spkr.python.service : sudo systemctl stop spkr.python.service
  3. Start it again : spkr.python.service : sudo systemctl start spkr.python.service
  4. You can check the service runs by issuing : sudo systemctl status spkr.python.service -l

Now speak in your microphone, and try queries such as : Hey Snips <mark a pause>, play Michael Jackson.

If it still doesn’t work, can you please :

  1. Show me the output of less /etc/systemd/system/spkr.python.service
  2. Show me the output of less /etc/systemd/system/spkr.snips.service
  3. Download this assistant
  4. Move the file to your raspberry pi, and issue a snips-install-asssistant SPKR_ASSISTANT.zip
  5. Reboot your raspberry, and perform the steps explained before.

Hope this will help :v:t5: !


#8

Still no luck, nothing on the assistant link above.

Just to let you know, I could not get mopidysetup.sh to start so I used a config file from a previous setup of mopidy, it works but just a bit concerned this could be causing problems.
Also the assistant wasn’t in the original setup so I followed the instructions on a previous query to download & install the music one from the site
sudo systemctl status spkr.python.service -l
● spkr.python.service - snips Python Service
Loaded: loaded (/lib/systemd/system/spkr.python.service; enabled)
Active: active (running) since Fri 2017-08-25 15:46:44 UTC; 41s ago
Main PID: 1662 (python)
CGroup: /system.slice/spkr.python.service
└─1662 /usr/bin/python /home/pi/home-python/home

Aug 25 15:46:44 spkr systemd[1]: Started snips Python Service.
Aug 25 15:46:45 spkr python[1662]: sounds/wake1.wav: No such file or directory

less /etc/systemd/system/spkr.python.service
[Unit]
Description=snips Python Service
After=spkr.snips.service

[Service]
Type=simple
ExecStart=/usr/bin/python /home/pi/home-python/home

[Timer]
OnStartupSec=5

[Install]
WantedBy=multi-user.target
Alias=spkr.python.service

less /etc/systemd/system/spkr.snips.service
less /etc/systemd/system/spkr.python.service
[Unit]
Description=snips Python Service
After=spkr.snips.service

[Service]
Type=simple
ExecStart=/usr/bin/python /home/pi/home-python/home

[Timer]
OnStartupSec=5

[Install]
WantedBy=multi-user.target
Alias=spkr.python.service
~
~
~
~
~
~
~
~
~
(END)


#9

Hi Anthony,

I’ve now reinstalled everything - got the mopidy_setup.sh to run by giving it permission chmod 777 so we have the correct mopidy setup.
When trying to restart the python service it seems as though it can’t find wake1.wav and then it enters a fail state.

I know the file wake1.wav is there.

Aug 26 12:03:07 spkr python[450]: sounds/wake1.wav: No such file or directory
Aug 26 12:03:07 spkr systemd[1]: spkr.python.service: main process exited, code=exited, status=1/FAILURE
Aug 26 12:03:07 spkr systemd[1]: Unit spkr.python.service entered failed state.


#10

Hey @steve,

I think that the script not finding the .wav file doesn’t cause the script to crash.

Starting the spkr.snips.service launches a docker container. In this container, a MQTT broker is run.
The spkr.python.service has a MQTT client that tries to connect to this MQTT broker.

What may cause the crash of the script is that the spkr.python.service tries to connect before the MQTT broker in the spkr.snips.service is started.

This week, we’ll push an update to spkr image, and the blog post ! In the meantime, try to restart the spkr.python.service long after the spkr.snips.service has started.

I updated the code for relay.py , don’t hesitate to do it too :

from __future__ import absolute_import, unicode_literals

import json
import time

import paho.mqtt.client as mqtt

from datetime import datetime
from music import Music
from state_service import StateService, State


DEBUG = False

MQTT_HOST = 'spkr.local' if DEBUG else 'localhost'
BASE_URL = 'http://spkr.local:6680' if DEBUG else 'http://localhost:6680'

MQTT_CHANNEL_SEARCH_MUSIC = 'hermes/intent/PlayMusicCreativeWork'
MQTT_CHANNEL_PLAY_PLAYLIST = 'hermes/intent/PlayMusicPlaylist'
MQTT_CHANNEL_PLAY = 'hermes/intent/ResumeMusicCreativeWork'
MQTT_CHANNEL_STOP = 'hermes/intent/StopMusicCreativeWork'
MQTT_CHANNEL_PAUSE = 'hermes/intent/SuspendMusicCreativeWork'
MQTT_CHANNEL_NEXT_TRACK = 'hermes/intent/NextIntent'
MQTT_CHANNEL_PREVIOUS_TRACK = 'hermes/intent/PreviousIntent'
MQTT_CHANNEL_STT_SPEECH = 'hermes/Speech'
MQTT_CHANNEL_STT_HOTWORD = 'hermes/asr/toggleOn'

PRINT_LOGS = True
current_volume = 0
VOLUME_WHILE_LISTENING = 40
MIN_VOLUME = 25


def process_stt_feedback(music, event):
    if event == 'SPEECH_ON':
        global current_volume
        current_volume = music.get_volume()
        music.set_volume(VOLUME_WHILE_LISTENING)
        return 'Speech ON'

    elif event == 'SPEECH_OFF':
        global current_volume
        music.set_volume(max(MIN_VOLUME, current_volume))
        return 'Speech OFF'

    return 'Speech in unrecognized state'


def process_sdk_msg(music, sdk_msg, state):
    slots = json.loads(sdk_msg)["slots"]
    type = json.loads(sdk_msg)['intent']['intentName']


    if type is None:
        return 'no type found'

    elif 'PreviousIntent' == type:
        music.previous()
        state.set_state(State.found_high)
        return 'Previous track'
    
    elif 'NextIntent' == type:
        music.next()
        state.set_state(State.found_high)
        return 'Next track'

    elif 'ResumeMusicCreativeWork' == type:
        music.play()
        state.set_state(State.found_high)
        return 'Play music'

    elif 'SuspendMusicCreativeWork' == type:
        music.pause()
        state.set_state(State.found_high)
        return 'Pause music'

    elif 'StopMusicCreativeWork' == type:
        music.pause()
        state.set_state(State.found_high)
        return 'Stop music'

    elif 'PlayMusicPlaylist' == type:
        playlist = None

        for slot in slots:
            if ('slotName') in slot:
                slot_name = slot['slotName']
                if 'musicPlaylistName' == slot_name:
                    playlist = slot['value']

        if playlist is not None and 0 != len(playlist):
            state.set_state(State.found_high)
            music.set_playlist(playlist)
            music.play_first()
            return 'Playing playlist'

    elif 'PlayMusicCreativeWork' == type:
        genre = None
        track_album_artist = None
        mood = None

        for slot in slots:
            if 'slotName' in slot:
                slot_name = slot['slotName']
                if 'musicCreativeWorkGenre' == slot_name:
                    genre = slot['value']
                if 'musicCreativeWorkArtistName' == slot_name:
                    track_album_artist = slot['value']['value']
                if 'musicCreativeWorkName' == slot_name:
                    track_album_artist = slot['value']['value']

        if genre is not None and 0 != len(genre):
            state.set_state(State.found_high)
            music.set_search(music.search_genre(genre))
            music.shuffle()
            music.play_first()
            return 'playing genre "' + genre + '"'

        elif track_album_artist is not None and 0 != len(track_album_artist):
            if "Nickelback" in track_album_artist:
                state.set_state(State.error)
                time.sleep(3)
                state.set_state(State.error)
                return None
            else:
                state.set_state(State.found_high)
                music.set_search(
                    music.search_any(track_album_artist)
                )
                music.play_first()
            return 'playing songs related to "' + track_album_artist + '"'
        elif mood is not None and 0 != len(mood):
            print("can't handle mood")
            state.set_state(State.error)
        else:
            state.set_state(State.error)
            return 'invalid query ' + json.dumps(query)
    else:
        state.set_state(State.error)
        return 'unkown type ' + type


class Relay():
    def __init__(self):
        self.mqttc = mqtt.Client()
        self.music = Music(BASE_URL)
        self.state = StateService()

        self.mqttc.on_message = self.on_message
        self.mqttc.on_connect = self.on_connect
        self.mqttc.on_publish = self.on_publish
        self.mqttc.on_subscribe = self.on_subscribe

        self.mqttc.on_log = self.on_log

    def on_connect(self, mqttc, obj, flags, rc):
        print('Connected to host')
        self.mqttc.subscribe(MQTT_CHANNEL_SEARCH_MUSIC, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_PLAY_PLAYLIST, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_PLAY, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_STOP, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_PAUSE, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_NEXT_TRACK, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_PREVIOUS_TRACK, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_STT_SPEECH, 0)
        self.mqttc.subscribe(MQTT_CHANNEL_STT_HOTWORD, 0)

    def on_message(self, mqttc, obj, msg):
        print('Received message on' + ' ' + msg.topic + ' ' + msg.payload)
        print(msg.topic)
        start = datetime.now()
        response = None
        if msg.topic == '/hermes/speaker/state':
            response = self.state.process_state_msg(msg.payload)
        
        elif msg.topic == MQTT_CHANNEL_STT_HOTWORD:
            response = process_stt_feedback(self.music, "SPEECH_OFF")
            self.state.set_state(State.found_low)
            # response = self.state.process_state_msg(State.found_low)
        
        elif msg.topic == MQTT_CHANNEL_STT_SPEECH:
            response = process_stt_feedback(self.music, "SPEECH_ON")
            self.state.set_state(State.loading)

        else:
            try:
                response = process_sdk_msg(self.music, msg.payload, self.state)
            except:
                pass

            if response is None:
                self.mqttc.publish("/hermes/mopidy/error", payload="error")
            else:
                self.mqttc.publish("/hermes/mopidy/success", payload="success")

        end = datetime.now()
        print('Duration: {0}'.format(end - start))
        # response = process_mqtt_msg(self.music, msg)
        # response = process_sdk_msg(self.music, msg.payload)
        print(response)

    def on_publish(self, mqttc, obj, mid):
        print('mid: ' + str(mid))

    def on_subscribe(self, mqttc, obj, mid, granted_qos):
        print('Subscribed: ' + str(mid))

    def on_log(self, mqttc, obj, level, string):
        if PRINT_LOGS:
            print(string)
        return None

    def run(self):
        self.mqttc.connect(MQTT_HOST, 9898, 60)
        self.mqttc.loop_forever()

Cheers !


How to setup Mopidy / Spotify on a fresh Snips install
#11

Hi Anthony,

I’ve changed the relay.py as suggested and restarting spkr.python.service after 5 mins seems to make it run
this is the result of sudo systemctl status spkr.python.service
● spkr.python.service - snips Python Service
Loaded: loaded (/lib/systemd/system/spkr.python.service; enabled)
Active: active (running) since Mon 2017-08-28 12:46:34 UTC; 1min 31s ago
Main PID: 1563 (python)
CGroup: /system.slice/spkr.python.service
└─1563 /usr/bin/python /home/pi/home-python/home

Aug 28 12:46:34 spkr systemd[1]: Started snips Python Service.
Aug 28 12:46:34 spkr python[1563]: sounds/wake1.wav: No such file or directory

Now that the snips python service is running is there anything else I should check?


#12

Awesome !
It should work ! Plug a speaker to your jack output, and you can try querying :

  • Hey Snips
  • You should hear a little beep
  • play Michael Jackson

Tell me if this works !


#13

Hi Anthony,

Just tried, no beep and mopidy is stuck on finding Michael Jackson, but do feel we are getting somewhere now!!

Thanks so much for your help, fingers crossed a couple of reboots will sort out any other problems.

I’ll keep you posted, thanks again

Steve


#14

Hi Anthony,
any news on the updated image?

Steve


#15

Hi,
just to let you know as I were in the same situation.
I modified the relative path in the sounds.py to an absolute path

BASE = ‘/home/pi/home-python/home/sounds/’

It should work.


#16

Thanks for the advice, I’ve given up on snips as there seems to be nothing happening with it at the moment, but will try your solution when i set it up again. Will let you know how it goes.