diff options
Diffstat (limited to 'bin/main.py')
| -rw-r--r-- | bin/main.py | 102 |
1 files changed, 89 insertions, 13 deletions
diff --git a/bin/main.py b/bin/main.py index 17b506d..bf556ca 100644 --- a/bin/main.py +++ b/bin/main.py | |||
| @@ -2,12 +2,13 @@ import time | |||
| 2 | import os | 2 | import os |
| 3 | import speech_recognition as speech | 3 | import speech_recognition as speech |
| 4 | import sounddevice | 4 | import sounddevice |
| 5 | import i2c as lcd | 5 | import bin.hardware_driver as lcd |
| 6 | from gpiozero import CPUTemperature | 6 | from gpiozero import CPUTemperature |
| 7 | 7 | ||
| 8 | ERROR_BAD_REQUEST = "400 Bad Request" | 8 | ERROR_BAD_REQUEST = "400 Bad Request" |
| 9 | ERROR_UNAUTHORIZED = "401 Unauthorized" | 9 | ERROR_UNAUTHORIZED = "401 Unauthorized" |
| 10 | ERROR_NOT_FOUND = "404 Not Found" | 10 | ERROR_NOT_FOUND = "404 Not Found" |
| 11 | SPEECH_NOT_RECOGNIZED = "404-1 Speech is not recognized" | ||
| 11 | ERROR_TIMEOUT = "408 Request Timeout" | 12 | ERROR_TIMEOUT = "408 Request Timeout" |
| 12 | 13 | ||
| 13 | lcd_instance = lcd.LCD() | 14 | lcd_instance = lcd.LCD() |
| @@ -16,7 +17,46 @@ recognizer = speech.Recognizer() | |||
| 16 | microphone = speech.Microphone() | 17 | microphone = speech.Microphone() |
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | def display_cpu_info(): | 20 | # greeting that starts upon the boot of the device: |
| 21 | # shows a hello line; shorter than 16 chars | ||
| 22 | # and some small information on the second line | ||
| 23 | def custom_greeting(): | ||
| 24 | with open('quotes.txt', 'r') as file: | ||
| 25 | quotes = file.readlines() | ||
| 26 | |||
| 27 | # Strip newline characters and use the quotes | ||
| 28 | quotes = [quote.strip() for quote in quotes] | ||
| 29 | |||
| 30 | # Print the quotes | ||
| 31 | for quote in quotes: | ||
| 32 | print(quote) | ||
| 33 | first_line = "" | ||
| 34 | second_line = "" | ||
| 35 | count = 0 | ||
| 36 | for i in quote: | ||
| 37 | if count < 16: | ||
| 38 | first_line += i | ||
| 39 | count += 1 | ||
| 40 | else: | ||
| 41 | second_line += i | ||
| 42 | lcd.text(first_line,1) | ||
| 43 | lcd.text(secon_line,2) | ||
| 44 | def pomodoro(): | ||
| 45 | time = input("How long do you want to wait? : ") | ||
| 46 | print("Okay \nStarting Now...") | ||
| 47 | while time > 0: | ||
| 48 | time.sleep(1) | ||
| 49 | print(time + "Seconds") | ||
| 50 | lcd.text(time + " Seconds remaining...", 1) | ||
| 51 | time -= 1 | ||
| 52 | |||
| 53 | |||
| 54 | def weather(): | ||
| 55 | pass | ||
| 56 | |||
| 57 | |||
| 58 | # ram usage, internet speed, | ||
| 59 | def system_readings(): | ||
| 20 | lcd_instance.clear() | 60 | lcd_instance.clear() |
| 21 | while True: | 61 | while True: |
| 22 | load = os.getloadavg()[0] | 62 | load = os.getloadavg()[0] |
| @@ -37,6 +77,7 @@ def display_uptime(): | |||
| 37 | 77 | ||
| 38 | 78 | ||
| 39 | def recognize_speech(): | 79 | def recognize_speech(): |
| 80 | |||
| 40 | lcd_instance.clear() | 81 | lcd_instance.clear() |
| 41 | try: | 82 | try: |
| 42 | with microphone as source: | 83 | with microphone as source: |
| @@ -46,6 +87,7 @@ def recognize_speech(): | |||
| 46 | text = recognizer.recognize_google(audio) | 87 | text = recognizer.recognize_google(audio) |
| 47 | lcd_instance.clear() | 88 | lcd_instance.clear() |
| 48 | lcd_instance.text(text, 1) | 89 | lcd_instance.text(text, 1) |
| 90 | |||
| 49 | print("Speech recognized:", text) | 91 | print("Speech recognized:", text) |
| 50 | except speech.UnknownValueError: | 92 | except speech.UnknownValueError: |
| 51 | lcd_instance.text(ERROR_BAD_REQUEST, 1) | 93 | lcd_instance.text(ERROR_BAD_REQUEST, 1) |
| @@ -54,6 +96,8 @@ def recognize_speech(): | |||
| 54 | lcd_instance.text(ERROR_UNAUTHORIZED, 1) | 96 | lcd_instance.text(ERROR_UNAUTHORIZED, 1) |
| 55 | print(ERROR_UNAUTHORIZED) | 97 | print(ERROR_UNAUTHORIZED) |
| 56 | 98 | ||
| 99 | return text | ||
| 100 | |||
| 57 | 101 | ||
| 58 | def save_notes(): | 102 | def save_notes(): |
| 59 | print("Type your notes (type 'stop' to exit):") | 103 | print("Type your notes (type 'stop' to exit):") |
| @@ -61,32 +105,64 @@ def save_notes(): | |||
| 61 | while True: | 105 | while True: |
| 62 | line = 1 | 106 | line = 1 |
| 63 | output = input(":") | 107 | output = input(":") |
| 108 | output_length = len(output) | ||
| 64 | if output.lower() in ["stop", "break", "quit", "exit"]: | 109 | if output.lower() in ["stop", "break", "quit", "exit"]: |
| 65 | break | 110 | break |
| 66 | if output == "line=1": | 111 | if output == "line=1": |
| 67 | line = 1 | 112 | line = 1 |
| 68 | elif output == "line=2": | 113 | elif output == "line=2": |
| 69 | line = 2 | 114 | line = 2 |
| 70 | lcd_instance.text(output, line) | 115 | |
| 71 | time.sleep(2) | 116 | if output_length < 16: |
| 117 | lcd_instance.text(output, line) | ||
| 118 | time.sleep(2) | ||
| 119 | else: | ||
| 120 | output_list = output.split("") | ||
| 121 | first_line = "" | ||
| 122 | second_line = "" | ||
| 123 | for i in output_list: | ||
| 124 | count = 0 | ||
| 125 | if count > 16: | ||
| 126 | first_line += output_list[i] | ||
| 127 | count += 1 | ||
| 128 | else: | ||
| 129 | second_line += output_list[i] | ||
| 130 | lcd.text(first_line,1) | ||
| 131 | lcd.text(secon_line,2) | ||
| 132 | |||
| 133 | def command_center(commands): | ||
| 134 | # checking if we can reconize commands within the user speech | ||
| 135 | # requires -> | ||
| 136 | # converting the commands to human readable text | ||
| 137 | # no under scars | ||
| 138 | command = recognize_speech() | ||
| 139 | list = [] | ||
| 140 | try: | ||
| 141 | for i in commands: | ||
| 142 | if i == command: | ||
| 143 | print("I think i found what you ment...") | ||
| 144 | command() | ||
| 145 | except: | ||
| 146 | print("ERROR 404 - COMMAND NOT RECOGNIZED") | ||
| 72 | 147 | ||
| 73 | 148 | ||
| 74 | OPTIONS = { | 149 | FEATURES = { |
| 75 | "CPU_INFO": display_cpu_info, | 150 | "READINGS": system_readings, |
| 76 | "UPTIME": display_uptime, | 151 | "UPTIME": display_uptime, |
| 77 | "SPEECH_TRANSCRIBER": recognize_speech, | 152 | "SPEECH_TRANSCRIBER": recognize_speech, |
| 78 | "NOTES": save_notes, | 153 | "NOTES": save_notes, |
| 79 | } | 154 | "COMMAND CENTER": command_center, |
| 155 | } | ||
| 80 | 156 | ||
| 81 | 157 | ||
| 82 | def main(): | 158 | def main(): |
| 83 | lcd_instance.clear() | 159 | lcd_instance.clear() |
| 84 | print("WELCOME TO THE I2C COMMAND LINE CENTER") | 160 | os.system("cls" if os.name == "nt" else "clear") |
| 85 | print("Options:", ", ".join(OPTIONS.keys())) | 161 | print("FEATURES:", ", ".join(FEATURES.keys())) |
| 86 | 162 | ||
| 87 | while True: | 163 | while True: |
| 88 | user_input = input("Enter command: ").upper() | 164 | user_input = input("Enter command: ").upper() |
| 89 | action = OPTIONS.get(user_input) | 165 | action = FEATURES.get(user_input) |
| 90 | 166 | ||
| 91 | if action: | 167 | if action: |
| 92 | action() | 168 | action() |
