56 lines
1.2 KiB
Python
56 lines
1.2 KiB
Python
from scipy.io import wavfile
|
|
import sys
|
|
samplerate, data = wavfile.read('./output.wav')
|
|
|
|
if len(sys.argv) < 2:
|
|
print("Usage:", "python3", sys.argv[0], "<file.wav>")
|
|
exit(1)
|
|
|
|
i = 0
|
|
countsilent = 0
|
|
samplefound = 0
|
|
|
|
avg = []
|
|
start = 0
|
|
end = 0
|
|
avg.append([0])
|
|
|
|
for sample in data:
|
|
i+=1
|
|
if(sample[1]<100):
|
|
countsilent += 1
|
|
if(countsilent > 10000 and sample[1]>100):
|
|
countsilent = 0
|
|
#print(str(i)+": sample found")
|
|
start = i
|
|
samplefound = 1
|
|
if(countsilent > 8000 and samplefound==1):
|
|
samplefound = 0
|
|
#print(str(i)+": sample ended")
|
|
end = i
|
|
avg[len(avg)-1]=avg[len(avg)-1]/(end-start)
|
|
avg.append([0])
|
|
if (samplefound == 1):
|
|
avg[len(avg)-1] += sample[1]
|
|
|
|
alphabet = "abcdefghijklmnopqr stuvwxyz"
|
|
avgs = {}
|
|
|
|
i=0
|
|
|
|
res=""
|
|
|
|
for arr in avg:
|
|
value = round(arr[0], 2)
|
|
#print(value)
|
|
if str(value) not in avgs:
|
|
avgs[str(value)]=alphabet[i]
|
|
#print(str(value), "is", alphabet[i])
|
|
i+=1
|
|
res+=avgs[str(value)]
|
|
|
|
|
|
print(res)
|
|
print("\n")
|
|
print("plug the substitution cipher into https://www.guballa.de/substitution-solver and hope it worked!")
|