summaryrefslogtreecommitdiff
path: root/bin/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'bin/main.py')
-rw-r--r--bin/main.py109
1 files changed, 103 insertions, 6 deletions
diff --git a/bin/main.py b/bin/main.py
index 2231547..921082f 100644
--- a/bin/main.py
+++ b/bin/main.py
@@ -1,9 +1,106 @@
1import tk 1import time
2import source as main 2import os
3import speech_recognition as speech
4import sounddevice
5import i2c as LCD
6from gpiozero import CPUTemperature
3 7
4source = main() 8ERROR_BAD_REQUEST = "400 Bad Request"
9ERROR_UNAUTHORIZED = "401 Unauthorized"
10ERROR_NOT_FOUND = "404 Not Found"
11ERROR_TIMEOUT = "408 Request Timeout"
5 12
6display = tk.Tk() 13lcd = LCD
7display.title("Kasper") 14cpu_temp = CPUTemperature()
15recognizer = speech.Recognizer()
16microphone = speech.Microphone()
8 17
9display.mainloop() \ No newline at end of file 18
19def display_cpu_info():
20 lcd.clear()
21 while True:
22 load = os.getloadavg()[0]
23 temperature = cpu_temp.temperature
24 lcd.clear()
25 lcd.display_text(f"CPU Load:i {load}", 1)
26 lcd.display_text(f"Temp: {temperature:}C", 2)
27 time.sleep(5)
28
29
30def display_uptime():
31 lcd.clear()
32 with open("/proc/uptime") as f:
33 uptime_seconds = float(f.readline().split()[0])
34 uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds))
35 lcd.clear()
36 lcd.display_text(f"Uptime: {uptime_str}", 1, "center")
37
38
39def recognize_speech():
40 lcd.clear()
41 try:
42 with microphone as source:
43 recognizer.adjust_for_ambient_noise(source)
44 print("Listening...")
45 audio = recognizer.listen(source)
46 text = recognizer.recognize_google(audio)
47 lcd.clear()
48 lcd.display_text(text, 1)
49 print("Speech recognized:", text)
50 except speech.UnknownValueError:
51 lcd.display_text(ERROR_BAD_REQUEST, 1)
52 print(ERROR_BAD_REQUEST)
53 except speech.RequestError:
54 lcd.display_text(ERROR_UNAUTHORIZED, 1)
55 print(ERROR_UNAUTHORIZED)
56
57
58def save_notes():
59 PRINT_REQUEST = True
60 EXIT_CODES = ["stop", "break", "quit", "exit"]
61 if PRINT_REQUEST == True:
62 while True:
63 OUTPUT = input()
64 print(OUTPUT)
65 lcd.display_text(OUTPUT, 1)
66 time.sleep(2)
67 for i in EXIT_CODES:
68 if OUTPUT == i:
69 PRINT_REQUEST == False
70
71
72OPTIONS = {
73 "CPU_INFO": display_cpu_info(),
74 "UPTIME": display_uptime(),
75 "SPEECH_TRANSCRIBER": recognize_speech(),
76 "NOTES": save_notes(),
77}
78
79
80def main():
81 lcd.clear()
82 print("WELCOME TO THE I2C COMMAND LINE CENTER")
83 print("Options:", ", ".join(OPTIONS.keys()))
84
85 while True:
86 user_input = input("Enter command: ").upper()
87 action = OPTIONS.get(user_input)
88
89 if action:
90 action()
91 else:
92 lcd.display_text(ERROR_NOT_FOUND, 1)
93 print(ERROR_NOT_FOUND)
94
95
96def destroy():
97 lcd.clear()
98 os.system("cls" if os.name == "nt" else "clear")
99
100
101if __name__ == "__main__":
102 os.system("cls" if os.name == "nt" else "clear")
103 try:
104 main()
105 except KeyboardInterrupt:
106 destroy()