-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (34 loc) · 1.57 KB
/
main.py
File metadata and controls
40 lines (34 loc) · 1.57 KB
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
from encode import Encode
from decode import Decode
def main():
print("[E]ncode a plaintext message into a Morse audio file")
print("[D]ecode a Morse audio file into a plaintext message")
choice = input("Choose an option: ").lower()
while not(choice == "e" or choice == "d"): # Force user to pick valid option
choice = input("Please choose a valid option: ").lower()
while True:
try:
# Ask for encode parameters
if choice == "e":
path = input("Enter the filename to save to (include file extension): ")
format = input("Enter the file's format (\"mp3\", \"wav\", etc.): ")
message = input("Enter the message to encode: ")
wpm = input("Enter the wpm to encode at: ")
enc_instance = Encode(path, format, message, wpm)
enc_instance.encode()
print("Message successfully encoded!")
# Ask for decode parameters
else:
path = input("Enter the filepath and filename (include file extension): ")
format = input("Enter the file's format (\"mp3\", \"wav\", etc.): ")
dec_instance = Decode(path, format)
decoded = dec_instance.decode()
print(f"Decoded message: '{decoded}'")
break # Quit program if successful
# Loop if error
except KeyboardInterrupt:
quit()
except Exception as e:
print("\nAn error ocurred, please enter valid parameters")
if __name__ == '__main__':
main()