Snips does not reply back after Pi restart until command sam install actions is given everytime

I have installed snips on a Pi. There are code snippets to say back something on detection of an intent which works fine most of the time. But after reboot of Pi, the snippet doesn’t seem to work as there is no tts output.
However it starts working again after giving command ‘sam install actions’ until next time Pi is rebooted.

After every reboot, this is the output of sam watch.

[19:40:57] [Hotword] detected on site default, for model hey_snips
[19:40:57] [Asr] was asked to stop listening on site default
[19:40:57] [Hotword] was asked to toggle itself 'off' on site default
[19:40:57] [Dialogue] session with id 'de1eab6b-8276-494c-91b0-5679377b10e1' was started on site default
[19:40:57] [AudioServer] was asked to play a wav of 41.1 kB with id '5b747e3f-3ee5-47ce-a254-02f4b2fc95f8' on site default
[19:40:57] [AudioServer] finished playing wav with id '5b747e3f-3ee5-47ce-a254-02f4b2fc95f8'
[19:40:57] [Asr] was asked to listen on site default
[19:40:59] [Asr] captured text "green" in 1.0s
[19:40:59] [Asr] was asked to stop listening on site default
[19:40:59] [AudioServer] was asked to play a wav of 93.1 kB with id '30608bd3-7bd8-42be-b712-787f181b70de' on site default
[19:41:00] [AudioServer] finished playing wav with id '30608bd3-7bd8-42be-b712-787f181b70de'
[19:41:00] [Nlu] was asked to parse input "green"
[19:41:00] [Nlu] detected intent adityakush:Color with confidence score 1.000 for input "green"
              Slots ->
                 color -> green (confidence: 1.000) 
[19:41:00] [Dialogue] New intent detected adityakush:Color with confidence 1.000
              Slots ->
                 color -> green (confidence: 1.000) 
[19:41:00] [Dialogue] was ask to end session with id de1eab6b-8276-494c-91b0-5679377b10e1
[19:41:00] [Dialogue] session with id 'de1eab6b-8276-494c-91b0-5679377b10e1' was ended on site default. The session ended as expected
[19:41:00] [Asr] was asked to stop listening on site default
[19:41:00] [Hotword] was asked to toggle itself 'on' on site default

After giving command ‘sam install actions’, output is

Checking for actions 
Python skill adityakush.OHOHOH has 1 snippet: 
	adityakush 
Generating actions based on the snippets, copying the actions in /var/lib/snips/skills 
INFO:snips_actions_templates_engine_lib: parsing snippets for app "/usr/share/snips/assistant/snippets/adityakush.OHOHOH"
INFO:snips_actions_templates_engine_lib: parsing snippets dir "/usr/share/snips/assistant/snippets/adityakush.OHOHOH/python2"
INFO:snips_actions_templates_engine_lib: parsed 4 snippets

Setting up Python actions 
Running setup.sh for adityakush.OHOHOH 
✖ Error setting up adityakush.OHOHOH, one or more actions might not be able to run. Reason :
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support

Checking actions for end-user parameters 
Relaunching snips-skill-server 
✔ Snips assistant is now running. Say hey_snips to start!

After this, output of sam watch is

[19:54:05] [Hotword] detected on site default, for model hey_snips
[19:54:05] [Asr] was asked to stop listening on site default
[19:54:05] [Hotword] was asked to toggle itself 'off' on site default
[19:54:05] [Dialogue] session with id 'f2d22dcb-297c-4c0b-8c3f-f9bf0c5f2f37' was started on site default
[19:54:05] [AudioServer] was asked to play a wav of 41.1 kB with id '8ca4f07a-08ca-4813-99cd-6de66585a22d' on site default
[19:54:06] [AudioServer] finished playing wav with id '8ca4f07a-08ca-4813-99cd-6de66585a22d'
[19:54:06] [Asr] was asked to listen on site default
[19:54:08] [Asr] captured text "green" in 2.0s
[19:54:08] [Asr] was asked to stop listening on site default
[19:54:08] [AudioServer] was asked to play a wav of 93.1 kB with id '9ea6f347-d7ba-44dd-a634-e38356bebc06' on site default
[19:54:09] [AudioServer] finished playing wav with id '9ea6f347-d7ba-44dd-a634-e38356bebc06'
[19:54:09] [Nlu] was asked to parse input "green"
[19:54:09] [Nlu] detected intent adityakush:Color with confidence score 1.000 for input "green"
              Slots ->
                 color -> green (confidence: 1.000) 
[19:54:09] [Dialogue] New intent detected adityakush:Color with confidence 1.000
              Slots ->
                 color -> green (confidence: 1.000) 
[19:54:09] [Dialogue] was ask to end session with id f2d22dcb-297c-4c0b-8c3f-f9bf0c5f2f37 by saying 'Okay, this color is good'
[19:54:09] [Tts] was asked to say "Okay, this color is good"
[19:54:09] [Dialogue] was ask to end session with id f2d22dcb-297c-4c0b-8c3f-f9bf0c5f2f37
[19:54:09] [Dialogue] session with id 'f2d22dcb-297c-4c0b-8c3f-f9bf0c5f2f37' was ended on site default. The session ended as expected
[19:54:09] [Asr] was asked to stop listening on site default
[19:54:09] [Hotword] was asked to toggle itself 'on' on site default
[19:54:12] [Tts] finished speaking with id '3a2519b9-1c35-4f2f-9e0b-b830b7336c97'

Please suggest a permanent solution for this. Giving command everytime after a reboot to make it work is a pain.

Hey,
can you also post your code snippet?

1 Like

Sure.

import random

say = ['Okay, turning on', 'turned on', 'Okay, turned on', 'Okay, switching on','Okay, switched on', 'Okay, on']
result_sentence = random.choice(say)
current_session_id = intentMessage.session_id
hermes.publish_end_session(current_session_id, result_sentence)

Mmh the snippet seems to be fine.
In the first watch log I can see that the DialogueManager was ask to end the session, but without a sentence. The command to end a session can only come from a skill, so I have no Idea why there is no sentence output with that…

Are other apps working after reboot?

Sorry, I forgot to mention, I use openhab for home automation. So, openhab ends the session over there. But the code snippet does not fire.

However if I give command sam install actions, tts starts working again.
I dont know what this command does on the snips unit. Maybe as a workaround, I can make a script to run at startup which runs commands ought to run by sam install actions.

Did you try to restart the snips-skill-server after reboot with
sam service restart snips-skill-server
?

1 Like

Where can I find commands run by sam install actions

Bingo. Does the trick.

Maybe the snips-skill-server is not in systemd autostart - you can try this on your Raspberry Pi (not with sam):
sudo systemctl enable snips-skill-server

1 Like

Great. You hit the Bull’s eye. Dumb me couldn’t figure that out.
Thanks a lot

Sorry I was too fast. Still not working after a reboot.

1 Like

No problem, then there is something that crashes your script.
Can you execute this command
sam service log
say your voice command for the snippet and post the output of this sam command here?

1 Like

Here it is

-- Logs begin at Sun 2019-11-03 22:26:12 IST. --
Nov 03 22:30:15 orangepilite snips-asr[1271]: INFO:snips_asr_lib::asr        : T0+2.419 lookup and post-processing done
Nov 03 22:30:15 orangepilite snips-asr[1271]: INFO:snips_asr_lib::asr        : decoded: [Recognition { decoded_string: "turn off fan", likelihood: 0.9912245, tokens: Some([Token { value: "turn", confidence: 1.0, time: (0.0, 0.45), range: 0..4 }, Token { value: "off", confidence: 0.9739039, time: (0.45, 0.6086117), range: 5..8 }, Token { value: "fan", confidence: 1.0, time: (0.6086117, 1.89), range: 9..12 }]) }]
Nov 03 22:30:15 orangepilite snips-asr[1271]: INFO:snips_asr_hermes::handler : Publishing the recognition
Nov 03 22:30:15 orangepilite snips-asr[1271]: INFO:snips_asr_hermes::handler : Preparing decoder
Nov 03 22:30:15 orangepilite snips-audio-server[1339]: INFO:snips_audio_alsa::playback       : Using ALSA output None ("") for "d8c82146-8148-4720-aaed-26c54436460b", WavSpec { channels: 2, sample_rate: 22050, bits_per_sample: 16, sample_format: Int }
Nov 03 22:30:17 orangepilite snips-audio-server[1339]: INFO:snips_audio_alsa::playback       : Playback for d8c82146-8148-4720-aaed-26c54436460b finished
Nov 03 22:30:17 orangepilite snips-tts[1352]: INFO:snips_tts_hermes: Received a play finished message from audio server with an unknown id 'd8c82146-8148-4720-aaed-26c54436460b'. Ignoring it.
Nov 03 22:30:17 orangepilite snips-dialogue[1345]: INFO:snips_dialogue_lib::coordinator::coordinator: Session [4c822b43-9691-4046-8e22-9e3c9f20e0c2]: closing session which was active: Nominal
Nov 03 22:30:17 orangepilite snips-dialogue[1345]: INFO:snips_dialogue_lib::coordinator::coordinator: Site [default]: reset site -> turn off ASR and turn on Hotword
Nov 03 22:30:17 orangepilite snips-hotword[1342]: INFO:snips_hotword_lib::audio    : Audio thread for site default started.
Nov 03 22:33:02 orangepilite snips-hotword[1342]: INFO:snips_hotword_hermes        : Hotword detected: site_id:default model:hey_snips (154ms ago)
Nov 03 22:33:02 orangepilite snips-dialogue[1345]: INFO:snips_dialogue_lib::coordinator::coordinator: Site [default]: reset site -> turn off ASR and turn off Hotword
Nov 03 22:33:02 orangepilite snips-dialogue[1345]: INFO:snips_dialogue_lib::coordinator::coordinator: Session [8d60a2ee-71b2-4599-9ca4-79be39899981]: The session has been created because the site "default" is free
Nov 03 22:33:02 orangepilite snips-audio-server[1339]: INFO:snips_audio_alsa::playback       : Using ALSA output None ("") for "5e2e6a0a-dfaa-470d-8cb1-899cb20a54c5", WavSpec { channels: 2, sample_rate: 22050, bits_per_sample: 16, sample_format: Int }
Nov 03 22:33:02 orangepilite snips-hotword[1342]: INFO:snips_hotword_lib::audio    : Audio thread for site default stopped.
Nov 03 22:33:02 orangepilite snips-audio-server[1339]: INFO:snips_audio_alsa::playback       : Playback for 5e2e6a0a-dfaa-470d-8cb1-899cb20a54c5 finished
Nov 03 22:33:02 orangepilite snips-tts[1352]: INFO:snips_tts_hermes: Received a play finished message from audio server with an unknown id '5e2e6a0a-dfaa-470d-8cb1-899cb20a54c5'. Ignoring it.
Nov 03 22:33:02 orangepilite snips-asr[1271]: INFO:snips_asr_hermes::handler : Listening at site id default
Nov 03 22:33:02 orangepilite snips-asr[1271]: INFO:snips_asr_hermes::handler : Listening
Nov 03 22:33:02 orangepilite snips-asr[1271]: INFO:snips_asr_lib::asr        : T0       entered AsrRunner::run
Nov 03 22:33:02 orangepilite snips-asr[1271]: INFO:snips_asr_lib::asr        : T0+0.000 capture started
Nov 03 22:33:05 orangepilite snips-asr[1271]: INFO:snips_asr_lib::asr        : T0+2.887 endpoint detected (rule:4) frame:155 samples:39680 signal_time:2.48 rtf:0.692
Nov 03 22:33:05 orangepilite snips-asr[1271]: INFO:snips_asr_lib::asr        : T0+2.899 capture ended
Nov 03 22:33:05 orangepilite snips-asr[1271]: INFO:snips_asr_lib::asr        : T0+2.902 decoder finalized
Nov 03 22:33:05 orangepilite snips-asr[1271]: INFO:snips_asr_lib::asr        : T0+2.923 lookup and post-processing done
Nov 03 22:33:05 orangepilite snips-asr[1271]: INFO:snips_asr_lib::asr        : decoded: [Recognition { decoded_string: "turn off fan", likelihood: 0.98295444, tokens: Some([Token { value: "turn", confidence: 1.0, time: (0.0, 0.87), range: 0..4 }, Token { value: "off", confidence: 0.9497301, time: (0.87, 1.2945243), range: 5..8 }, Token { value: "fan", confidence: 1.0, time: (1.2945243, 2.31), range: 9..12 }]) }]
Nov 03 22:33:05 orangepilite snips-asr[1271]: INFO:snips_asr_hermes::handler : Publishing the recognition
Nov 03 22:33:05 orangepilite snips-asr[1271]: INFO:snips_asr_hermes::handler : Preparing decoder
Nov 03 22:33:05 orangepilite snips-audio-server[1339]: INFO:snips_audio_alsa::playback       : Using ALSA output None ("") for "3d08c5e4-a76f-4ae2-afdd-369e203895bb", WavSpec { channels: 2, sample_rate: 22050, bits_per_sample: 16, sample_format: Int }
Nov 03 22:33:06 orangepilite snips-audio-server[1339]: INFO:snips_audio_alsa::playback       : Playback for 3d08c5e4-a76f-4ae2-afdd-369e203895bb finished
Nov 03 22:33:06 orangepilite snips-tts[1352]: INFO:snips_tts_hermes: Received a play finished message from audio server with an unknown id '3d08c5e4-a76f-4ae2-afdd-369e203895bb'. Ignoring it.
Nov 03 22:33:07 orangepilite snips-dialogue[1345]: INFO:snips_dialogue_lib::coordinator::coordinator: Session [8d60a2ee-71b2-4599-9ca4-79be39899981]: closing session which was active: Nominal
Nov 03 22:33:07 orangepilite snips-dialogue[1345]: INFO:snips_dialogue_lib::coordinator::coordinator: Site [default]: reset site -> turn off ASR and turn on Hotword
Nov 03 22:33:07 orangepilite snips-hotword[1342]: INFO:snips_hotword_lib::audio    : Audio thread for site default started.

sudo systemctl restart snips-skill-server
does the trick. Just let me confirm a second time
Edit: Yes it does.
What could be the reson behind that??

Snips receives the session-end message from the script with the code snippet after the session has already been ended by OpenHAB - so you should deactivate whatever you have running on the OpenHAB which ends all sessions without a reason.

Snips dialogues work like this:
-> Hotword
-> DialogueManager starts session with specific ID
-> MQTT script executes action, because it received intent
-> script answers dialogueManager to end session with this ID
-> dialogueManager ends session with this ID

Yeah but this works as intended after restarting snips-skill-server.service
What could be the solution then? Do I need to remove end session command from openhab or should I just add a startup script to restart this service .

end session command from openhab

Why do you have an end session command without an answer on OpenHAB although you want to let the snippet end the session with an answer?

Do I need to remove end session command from openhab or should I just add a startup script to restart this service .

A better solution as a startup script would be that you remove the end session thing from OpenHAB

I am really new to all this stuff. I had setup openhab first and now getting to snips. I think it would be better to simply get answer from openhab side. But I am afraid I dnt know how to do that.

Okay, I’ll do that right away and report back.

Okay, but sadly I have no experience with OpenHAB, I use HomeAssistant.
I recommend you to make the things clear and do not cross OpenHAB with the snippet solution, because then it will end like this, OpenHAB gives an answer and ends the session, but you wait for the answer from the snippet.