summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authornasrlol <nsrddyn@gmail.com>2024-12-03 02:16:10 +0100
committernasrlol <nsrddyn@gmail.com>2024-12-03 02:16:10 +0100
commit276696553946550412c10e3557966a685b5095c2 (patch)
tree656967e0e1d10ed4d07cc0c91957ebe4c6eb3efe /source
parente4051088663b541a245b62e5ac5b6547d043b1cd (diff)
removed the availability bit
Diffstat (limited to 'source')
-rw-r--r--source/features.py77
1 files changed, 34 insertions, 43 deletions
diff --git a/source/features.py b/source/features.py
index 82092d4..e06bacb 100644
--- a/source/features.py
+++ b/source/features.py
@@ -24,30 +24,29 @@ lcd_instance = lcd.LCD()
24# try initializing the temperature readings 24# try initializing the temperature readings
25try: 25try:
26 cpu_temp = CPUTemperature() 26 cpu_temp = CPUTemperature()
27 temperature_available = 1 27
28except Exception as e: 28except Exception as e:
29 print("Error initializing CPU temperature sensor:", e) 29 print("Error initializing CPU temperature sensor:", e)
30 temperature_available = 0 30
31 31
32# try initializing the google speech recognizer 32# try initializing the google speech recognizer
33try: 33try:
34 recognizer = sr.Recognizer() 34 recognizer = sr.Recognizer()
35 recognizer_available = 1 35
36except Exception as e: 36except Exception as e:
37 print( 37 print(
38 "Error initialzing voice recognition, its possible the speech recognition module isn't installed" 38 "Error initialzing voice recognition, its possible the speech recognition module isn't installed"
39 ) 39 )
40 recognizer_available = 0 40
41 41
42# try initializing the microphone 42# try initializing the microphone
43try: 43try:
44 microphone = sr.Microphone() 44 microphone = sr.Microphone()
45 microphone_available = 1 45
46except Exception as e: 46except Exception as e:
47 print( 47 print(
48 "Error initialzing the microphone \n check if the sound device package is installed" 48 "Error initialzing the microphone \n check if the sound device package is installed"
49 ) 49 )
50 microphone_available = 0
51 50
52 51
53class feat: 52class feat:
@@ -108,20 +107,15 @@ class feat:
108 lcd_instance.text("Invalid input", 1) 107 lcd_instance.text("Invalid input", 1)
109 time.sleep(2) 108 time.sleep(2)
110 109
111 def temperature(self, temperature_available): 110 def temperature(self):
112
113 self.clear_terminal_lcd() 111 self.clear_terminal_lcd()
114 112 while True:
115 if temperature_available == 0: 113 load = os.getloadavg()[0]
116 print(ERROR_NOT_FOUND) 114 temperature = cpu_temp.temperature if cpu_temp else "N/A"
117 else: 115 lcd_instance.clear()
118 while True: 116 lcd_instance.text(f"CPU Load: {load:.2f}", 1)
119 load = os.getloadavg()[0] 117 lcd_instance.text(f"Temp: {temperature}C", 2)
120 temperature = cpu_temp.temperature if cpu_temp else "N/A" 118 time.sleep(5)
121 lcd_instance.clear()
122 lcd_instance.text(f"CPU Load: {load:.2f}", 1)
123 lcd_instance.text(f"Temp: {temperature}C", 2)
124 time.sleep(5)
125 119
126 def display_uptime(self): 120 def display_uptime(self):
127 self.clear_terminal_lcd() 121 self.clear_terminal_lcd()
@@ -135,33 +129,30 @@ class feat:
135 lcd_instance.text("Error reading uptime", 1) 129 lcd_instance.text("Error reading uptime", 1)
136 print("Error:", e) 130 print("Error:", e)
137 131
138 def recognize_speech(self, recognizer_available): 132 def recognize_speech(self, recognizer_):
139 self.clear_terminal_lcd() 133 self.clear_terminal_lcd()
140 if recognizer_available == 0 or microphone_available == 0:
141 print(ERROR_NOT_FOUND)
142 else:
143 134
144 lcd_instance.text("Listening...", 1) 135 lcd_instance.text("Listening...", 1)
145 try: 136 try:
146 with microphone as source: 137 with microphone as source:
147 recognizer.adjust_for_ambient_noise(source) 138 recognizer.adjust_for_ambient_noise(source)
148 audio = recognizer.listen(source) 139 audio = recognizer.listen(source)
149 output = recognizer.recognize_google(audio) 140 output = recognizer.recognize_google(audio)
150 lcd_instance.text("Recognized:", 1) 141 lcd_instance.text("Recognized:", 1)
151 lcd_instance.text(output[:16], 2) 142 lcd_instance.text(output[:16], 2)
152 143
153 print("Speech recognized:", output) 144 print("Speech recognized:", output)
154 return output 145 return output
155 except sr.UnknownValueError: 146 except sr.UnknownValueError:
156 lcd_instance.text(SPEECH_NOT_RECOGNIZED, 1) 147 lcd_instance.text(SPEECH_NOT_RECOGNIZED, 1)
157 print(SPEECH_NOT_RECOGNIZED) 148 print(SPEECH_NOT_RECOGNIZED)
158 except sr.RequestError as e: 149 except sr.RequestError as e:
159 lcd_instance.text(ERROR_UNAUTHORIZED, 1) 150 lcd_instance.text(ERROR_UNAUTHORIZED, 1)
160 print(ERROR_UNAUTHORIZED, e) 151 print(ERROR_UNAUTHORIZED, e)
161 except Exception as e: 152 except Exception as e:
162 lcd_instance.text("Speech Error", 1) 153 lcd_instance.text("Speech Error", 1)
163 print("Error:", e) 154 print("Error:", e)
164 return None 155 return None
165 156
166 def save_notes(self): 157 def save_notes(self):
167 self.clear_terminal_lcd() 158 self.clear_terminal_lcd()