summaryrefslogtreecommitdiff
path: root/bin/source.py
diff options
context:
space:
mode:
Diffstat (limited to 'bin/source.py')
-rw-r--r--bin/source.py106
1 files changed, 0 insertions, 106 deletions
diff --git a/bin/source.py b/bin/source.py
deleted file mode 100644
index 485cc03..0000000
--- a/bin/source.py
+++ /dev/null
@@ -1,106 +0,0 @@
1import time
2import os
3import speech_recognition as speech
4import sounddevice
5import i2c as LCD
6from gpiozero import CPUTemperature
7
8ERROR_BAD_REQUEST = "400 Bad Request"
9ERROR_UNAUTHORIZED = "401 Unauthorized"
10ERROR_NOT_FOUND = "404 Not Found"
11ERROR_TIMEOUT = "408 Request Timeout"
12
13lcd = LCD
14cpu_temp = CPUTemperature()
15recognizer = speech.Recognizer()
16microphone = speech.Microphone()
17
18
19def display_cpu_info():
20 lcd.clear()
21 while True:
22 load = os.getloadavg()[0] # 1-minute load average
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
72
73OPTIONS = {
74 "CPU_INFO": display_cpu_info(),
75 "UPTIME": display_uptime(),
76 "SPEECH_TRANSCRIBER": recognize_speech(),
77 "NOTES": save_notes(),
78}
79
80
81def main():
82 lcd.clear()
83 print("WELCOME TO THE I2C COMMAND LINE CENTER")
84 print("Options:", ", ".join(OPTIONS.keys()))
85
86 while True:
87 user_input = input("Enter command: ").upper()
88 action = OPTIONS.get(user_input)
89
90 if action:
91 action()
92 else:
93 lcd.display_text(ERROR_NOT_FOUND, 1)
94 print(ERROR_NOT_FOUND)
95
96
97def destroy():
98 lcd.clear()
99 os.system("cls" if os.name == "nt" else "clear")
100
101
102if __name__ == "__main__":
103 try:
104 main()
105 except KeyboardInterrupt:
106 destroy()