-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
33 lines (24 loc) · 1.03 KB
/
main.py
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
#!/bin/sh
import os
import sys
from time import sleep
#if len(sys.argv) != 4: print("usage: python main.py <freq> <file>"); exit()
frequency = sys.argv[len(sys.argv)-2] #hz
letters = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','Ñ','O','P','Q','R','S','T','U','V','W','X','Y','Z']
morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","--.--","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
def play(r: str):
if r == "\n": sleep(1.5)
elif r == " ": sleep(0.5)
elif r == ".":
os.system(f"play -qn -c1 synth {200/1000} sine {frequency}")
elif r == "-":
os.system(f"play -qn -c1 synth {400/1000} sine {frequency}")
def string_to_pseudomorse(string):
for i in range(len(letters)):
string = string.replace(letters[i], morse[i])
return string
text = open(sys.argv[len(sys.argv)-1],'r').read()
text = string_to_pseudomorse(text.upper())
print(text, len(letters), len(morse))
for i in range(len(text)):
play(text[i])