-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_contents_audio_out_fsk.py
46 lines (42 loc) · 1.22 KB
/
file_contents_audio_out_fsk.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
34
35
36
37
38
39
40
41
42
43
44
45
46
import time
import winsound
f = open('test_file.txt', 'w')
print f
#f.write("Audio Networking using ultrasound") #Write into Text file
f.write("Audio") #Write into Text file
f = open('test_file.txt', 'r+') #Open file for Read & Write
file_content = f.read() #Read from Text file
print 'Contents of text file :',file_content
len_file = len(file_content)
#print abcd[0]
Freq0 = 17000
Freq1 = 22000
duration = 500
ascii_values = [ord(c) for c in file_content]
#print ascii_values
binary_values = []
#len_ascii = len(values)
for i in range(len_file):
temp = bin(ascii_values[i])[2:]
len_temp = len(temp)
if (len_temp < 8):
for j in range(8-len_temp):
temp = '0' + temp
binary_values.append(temp)
len_bv = len(binary_values);
if (len_bv == len_file):
print 'True'
else:
print 'False'
#print len_bv
for j in range(len_bv):
for k in range(8):
if (binary_values[j][k] == '1'):
winsound.Beep(Freq1,duration)
else:
if(binary_values[j][k] == '0'):
winsound.Beep(Freq0,duration)
#print (bin(values[4])[2:])
f.close()
#f1.close()
#time.sleep(2) #2 seconds time delay