-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMorse code in python
More file actions
71 lines (47 loc) · 1.77 KB
/
Morse code in python
File metadata and controls
71 lines (47 loc) · 1.77 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import platform
text=""
text= raw_input("enter word to be played back in morse code:")
length= len(text)
alphabets=["","10","0111","0101","011","1","1101","001","1111","11","1000","010","1011","00","01","000","1001","0010","101","111","0","110","1110","100","0110","0100","0011"]
# added the first string as "" so that alphabets position remain unchanged i.e 1-26
the_platform = platform.system()
if( the_platform == 'Windows' ):
import winsound
for i in range(0,length):
#print text[i]
#ascii= ord(text[i]) #letter to ascii
#ascii= int(ascii) - 96 # so that alphabets lie in 1-26
ascii= int(ord(text[i])) - 96
a= str(alphabets[ascii])
l= len(a)
for j in range(0,l):
if( int(a[j]) == 1 ):
print "1"
winsound.Beep(1000,0.125*1000) #winsound module -- time is in microseconds, hence has to be multiplied by 1000
winsound.Beep(1000,0.055*1000)
elif( int(a[j]) == 0):
print "0"
winsound.Beep(1000,0.25*1000)
winsound.Beep(1000,0.055*1000)
else:
for i in range(0,length):
#print text[i]
#ascii= ord(text[i]) #letter to ascii
#ascii= int(ascii) - 96 # so that alphabets lie in 1-26
ascii= int(ord(text[i])) - 96
a= str(alphabets[ascii])
l= len(a)
# 1- short note
# 0 - long note
# a- duration
# b- frequency
for j in range(0,l):
if( int(a[j]) == 1 ):
print "1"
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % ( 0.125, 1000))
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % ( 0.055, 0))
elif( int(a[j]) == 0):
print "0"
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % ( 0.25, 1000))
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % ( 0.055, 0))