-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbercow.py
36 lines (27 loc) · 873 Bytes
/
bercow.py
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
35
36
import systemd.daemon
import os
import redis
def execute():
print('ORDER')
os.system('amixer set PCM unmute')
os.system('amixer set PCM 100%')
r = redis.Redis(host='192.168.0.1', port=6379,
db=0, decode_responses=True)
p = r.pubsub(ignore_subscribe_messages=True)
p.subscribe('bercow')
r.publish('services', 'bercow.on')
systemd.daemon.notify('READY=1')
print('ORDER')
try:
for message in p.listen():
cmd = message['data']
filepath = '/home/pi/zoidberg-deploy/bercow/Audio/' + cmd + '.WAV'
if os.path.isfile(filepath):
r.publish('bercow.speaker', cmd)
os.system('aplay ' + filepath + ' &')
except:
p.close()
r.publish('services', 'bercow.off')
print('ORDER')
if __name__ == '__main__':
execute()