forked from nerdaxic/glados-voice-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglados_respeaker.py
67 lines (53 loc) · 1.77 KB
/
glados_respeaker.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python3
import os
import glados_settings
glados_settings.load_from_file()
def respeaker_init():
# Try to load the ReSpeaker pixel ring library
if(glados_settings.settings["hardware"]["servo_controller"]["serial_enable"] in ('true', '1', 't')):
try:
from pixel_ring import pixel_ring
except Exception as e:
respeaker_errors(e)
# Parse error messages into most common help hints
def respeaker_errors(e):
if "Access denied" in str(e):
print("\nERROR: No permission to access ReSpeaker hardware.")
print("Check the README.md for udev rules in the hardware/respeaker folder.")
exit();
if "No such device" in str(e):
print("\nERROR: ReSpeaker is not connected.")
exit();
if "No such file of directory" in str(e):
print("\nERROR: Library missing.")
print("Run 'sudo pip3 install pixel_ring'")
exit();
if "name 'pixel_ring' is not defined" in str(e):
print("\nERROR: ReSpeaker is probably not connected?")
exit();
else:
print(e)
# Set the ring to static color.
# Input 8 bit HEX color codes
def respeaker_pixel_ring(rgb=0x100000):
# Set respeaker to dim glow inside the head.
# See hardware folder for more info.
if(glados_settings.settings["hardware"]["servo_controller"]["serial_enable"] in ('true', '1', 't')):
try:
pixel_ring.set_color(rgb)
except Exception as e:
respeaker_errors(e)
# Set respeaker to animation modes
def respeaker_mode(mode):
if(glados_settings.settings["hardware"]["servo_controller"]["serial_enable"] in ('true', '1', 't')):
if(mode == "listen"):
try:
pixel_ring.listen()
except Exception as e:
respeaker_errors(e)
elif(mode == "wait"):
try:
pixel_ring.wait()
except Exception as e:
respeaker_errors(e);
respeaker_init()