coding utf-8 from Tkinter import from tkMessageBox import from tkFileD

 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
72
73
74
75
76
77
78
79
80
81
# coding=utf-8
from Tkinter import *
from tkMessageBox import *
from tkFileDialog import *
from player import *
import wave
def scrambler(inner_file, out_file, interval_length):
interval_length = float(interval_length)
with open(inner_file, "rb") as wav_file:
wav_file_bytes = wav_file.read()
head = wav_file_bytes[:44]
data = wav_file_bytes[44:]
with open(inner_file, "rb") as wav_file:
wf = wave.open(wav_file, 'rb')
time = (1.0 * wf.getnframes()) / wf.getframerate()
interval_count = time / interval_length
interval_length = int(len(data)/interval_count) + 1
with open(out_file, "wb") as wav:
wav.write(head)
for j in range(0, len(data), interval_length):
string = data[j: j+interval_length]
wav.write(string[::-1])
showinfo('Scrambling', 'Successful!')
if __name__ == '__main__':
main_window = Tk()
main_window.title('Скремблирование аудио файлов')
main_window.minsize(500, 200)
main_window.geometry("+450+100")
inner_filename = StringVar(value="Выберите файл для скремблирования")
out_filename = StringVar(value="Выбирите файл результата")
interval_length = StringVar(value="Введите длительность сегмента")
frame_top = Frame()
frame_top.pack(pady=10, expand='True')
frame_mid = Frame()
frame_mid.pack(pady=10, expand='True')
frame_main = Frame()
frame_main.pack(pady=10, expand='True')
frame_bot = Frame()
frame_bot.pack(pady=10, expand='True')
Entry(frame_top, font="Arial 13", width=38, textvariable=inner_filename).pack(side='left', expand='True', padx=5)
Button(frame_top, text='Открыть', font="Arial 13",
command=lambda: inner_filename.set(askopenfilename())).pack(padx=5, expand='True')
Entry(frame_mid, font="Arial 13", width=38, textvariable=out_filename).pack(side='left', padx=5, expand='True')
Button(frame_mid, text='Открыть', font="Arial 13",
command=lambda: out_filename.set(asksaveasfilename())).pack(padx=5, expand='True')
Entry(frame_main, font="Arial 13", width=38, textvariable=interval_length).pack(side='left', padx=5, expand='True')
Button(main_window, text='Скремблировать', font="Arial 13",
command=lambda: scrambler(inner_filename.get(),
out_filename.get(),
interval_length.get())).pack(expand='True')
player = Player()
player.start()
Button(frame_bot, text='Проиграть', font="Arial 13",
command=lambda: player.play(out_filename.get())).pack(side='left', expand='True')
Button(frame_bot, text='Пауза', font="Arial 13", command=player.pause).pack(side='left', expand='True')
Button(frame_bot, text='Стоп', font="Arial 13", command=player.stop).pack(side='left', expand='True')
main_window.protocol('WM_DELETE_WINDOW', lambda: (player.close(), main_window.quit()))
main_window.mainloop()