-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_handler.py
More file actions
34 lines (24 loc) · 980 Bytes
/
custom_handler.py
File metadata and controls
34 lines (24 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
import sys
import json
import subprocess
def speech(text):
global o
o["speech"] = {"text": text}
# get json from stdin and load into python dict
o = json.loads(sys.stdin.read())
intent = o["intent"]["name"]
if(o.get("slots") is not None):
volume = o.get("slots").get("volume")
song = o.get("slots").get("song")
if intent == "AdjustVolume":
subprocess.call("amixer -c 1 set 'PCM',0 {}% > /dev/null 2>&1".format(volume),shell=True)
speech("Volume set to {} percent".format(volume))
elif intent == "PlaySong":
subprocess.call("play -q {} > /dev/null 2>&1".format(song),shell=True, env={"AUDIODEV":"hw:1,0"})
elif intent == "PlayKidSongs":
subprocess.call("play -q /media/black/music/kids/* > /dev/null 2>&1",shell=True, env={"AUDIODEV":"hw:1,0"})
elif intent == "StopMusic":
subprocess.call("ps -ef | pgrep play | xargs kill > /dev/null 2>&1",shell=True)
# convert dict to json and print to stdout
print(json.dumps(o))