-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
96 lines (70 loc) · 2.18 KB
/
Copy pathmain.py
File metadata and controls
96 lines (70 loc) · 2.18 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import sys
import types
try:
import pyaudioop as audioop # type: ignore
except ModuleNotFoundError:
try:
import audioop # type: ignore
except ModuleNotFoundError as exc:
raise RuntimeError("The audioop compatibility module is required for pydub on Python 3.13.") from exc
pyaudioop = types.ModuleType("pyaudioop")
for name in dir(audioop):
if not name.startswith("_"):
setattr(pyaudioop, name, getattr(audioop, name))
sys.modules["pyaudioop"] = pyaudioop
from pydub import AudioSegment
from tkinter import filedialog, messagebox
from threading import Thread
import customtkinter as ctk
root = ctk.CTk()
root.geometry('500x150')
root.title = 'Audio File Converter'
files_list = []
def get_file():
global files_list
# convert many of files if you want
file_names = filedialog.askopenfilenames()
for file in file_names:
files_list.append(file)
def convert_audio_files(src_file, from_, to_):
to_ = to_.lower()
funcs_list = {
'mp3': AudioSegment.from_mp3,
'wav': AudioSegment.from_wav,
'ogg': AudioSegment.from_ogg,
}
dist_file = src_file.replace(from_, to_)
# call function from dict
audio = funcs_list[from_](src_file)
audio.export(dist_file, format = to_)
def convert_files():
if len(files_list) <= 0:
messagebox.showinfo('Info', message='Choice files to convert')
for file_name in files_list:
extintion = file_name.split('.')[-1]
to_ = options.get()
convert_audio_files(file_name, extintion, to_=to_)
# add title
ctk.CTkLabel(root, text = root.title, font=('san-serf', 25)).place(x = 20, y = 10)
# add get file bt
bt_1 = ctk.CTkButton(
root,
text = 'Choice file',
command = get_file
)
bt_1.place(x = 20, y = 80)
# add extintions options
options = ctk.CTkOptionMenu(
root,
values = ('MP3', 'WAV', 'OGG')
)
options.place(x = 200, y = 80)
# add convert bt
bt_2 = ctk.CTkButton(
root,
text = 'Convert',
width=80,
command = lambda : convert_files()
)
bt_2.place(x = 350, y = 80)
root.mainloop()