init
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import wave
|
||||
import sys
|
||||
|
||||
alphabet="abcdefghijklmnopqrstuvwxyz "
|
||||
outfile = "output.wav"
|
||||
data= []
|
||||
|
||||
def usage():
|
||||
print("Usage:")
|
||||
print("python3", sys.argv[0], "<text>")
|
||||
print("<text> may only contain a-z and spaces")
|
||||
return
|
||||
|
||||
if len(sys.argv) < 2 or any(map(lambda char: not char in alphabet,sys.argv[1].lower())):
|
||||
usage()
|
||||
exit(1)
|
||||
|
||||
if(len(sys.argv[1]) < 250):
|
||||
print("WARNING: short texts may be much harder to break. You should use at least 250 characters")
|
||||
|
||||
input = sys.argv[1].lower()
|
||||
|
||||
print("Generating keyboard sounds for \"", input, "\"")
|
||||
|
||||
silence = wave.open("./data/silence.wav", 'rb')
|
||||
data.append([silence.getparams(), silence.readframes(silence.getnframes())])
|
||||
data.append([silence.getparams(), silence.readframes(silence.getnframes())])
|
||||
silence.close()
|
||||
|
||||
for char in input:
|
||||
if(char == " "):
|
||||
char = "spc"
|
||||
|
||||
sound_file = "./data/"+char+".wav"
|
||||
wav_data = wave.open(sound_file, 'rb')
|
||||
data.append([wav_data.getparams(), wav_data.readframes(wav_data.getnframes())])
|
||||
wav_data.close()
|
||||
|
||||
silence = wave.open("./data/silence.wav", 'rb')
|
||||
data.append([silence.getparams(), silence.readframes(silence.getnframes())])
|
||||
silence.close()
|
||||
|
||||
silence.close()
|
||||
|
||||
output = wave.open(outfile, 'wb')
|
||||
output.setparams(data[0][0])
|
||||
for i in range(len(data)):
|
||||
output.writeframes(data[i][1])
|
||||
output.close()
|
||||
|
||||
print("Your file is at", outfile)
|
||||
Reference in New Issue
Block a user