Código de Python - Editor de audio.

Imágen de perfil
Val: 712
Bronce
Ha aumentado 1 puesto en Python (en relación al último mes)
Gráfica de Python

Editor de audio.gráfica de visualizaciones


Python

Publicado el 13 de Octubre del 2021 por Antonio (57 códigos)
253 visualizaciones desde el 13 de Octubre del 2021
Aplicación para edición de audio que permite alterar características tales como la velocidad, volumen, ganancia... También permite invertir el sonido y almacenar el nuevo audio en distintos formatos (mp3, wav, ogg, mp4...)

Requerimientos

Lenguaje: Python
Librerías y recursos: Pygame, pydub, ffmpeg.

0.1

Publicado el 13 de Octubre del 2021gráfica de visualizaciones de la versión: 0.1
253 visualizaciones desde el 13 de Octubre del 2021
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

ae
PARA CUALQUIER DUDA U OBSERVACIÓN, UTILICEN LA SECCIÓN DE COMENTARIOS.
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
from tkinter import *
from tkinter import filedialog, messagebox
import tkinter.scrolledtext as sct
import os
from pygame import mixer
import threading
from pydub import AudioSegment
 
class editor():
    def __init__(self):
        self.root = Tk()
        self.root.geometry('923x375')
        self.root.title("Audio Editor")
        self.root.configure(bg="gray28")
 
        self.currentDir = StringVar()
        self.currentDir.set(os.getcwd())
        self.audioName = StringVar()
        self.audio = ""
        self.history = ""
        self.playing = False
        mixer.init()
 
        Entry(self.root,textvariable=self.currentDir,width=153).place(x=0,y=0)
        Label(self.root,text="AUDIO TITLE",fg="white",bg="gray28").place(x=10,y=30)
        self.entryName = Entry(self.root,textvariable=self.audioName,bg="black",fg="green",width=34,font=('arial 24'))
        self.entryName.place(x=10,y=53)
        #self.durationEntry = Entry(self.root,textvariable=self.duration,width=13,font=('arial 20'),bg="black",fg="red").place(x=690,y=53)
        #Label(self.root,text="DURATION(MINUTES)").place(x=690,y=30)
        Button(self.root,text="SEARCH AUDIO FILE",width=86,height=2,bg="gray70",command=self.open_file).place(x=12,y=100)
        Button(self.root,text="EXPORT AS .AU",width=15,height=2,bg="red",fg="white",command=lambda:self.init_task("au")).place(x=650,y=177)
        Button(self.root,text="EXPORT AS .AAC",width=15,height=2,bg="red",fg="white",command=lambda:self.init_task("aac")).place(x=797,y=301)#.place(x=797,y=53)
        Button(self.root,text="EXPORT AS .MP4",width=15,height=2,bg="red",fg="white",command=lambda:self.init_task("mp4")).place(x=650,y=301)#.place(x=650,y=115)
        Button(self.root,text="EXPORT AS .MP2",width=15,height=2,bg="red",fg="white",command=lambda:self.init_task("mp2")).place(x=797,y=239)#.place(x=797,y=115)
        Button(self.root,text="EXPORT AS .OGG",width=15,height=2,bg="red",fg="white",command=lambda:self.init_task("ogg")).place(x=650,y=239)#.place(x=650,y=177)
        Button(self.root,text="EXPORT AS .FLV",width=15,height=2,bg="red",fg="white",command=lambda:self.init_task("flv")).place(x=797,y=177)#.place(x=797,y=177)
        Button(self.root,text="EXPORT AS .MP3",width=15,height=2,bg="red",fg="white",command=lambda:self.init_task("mp3")).place(x=650,y=115)#.place(x=650,y=239)
        Button(self.root,text="EXPORT AS .WAV",width=15,height=2,bg="red",fg="white",command=lambda:self.init_task("wav")).place(x=797,y=115)#.place(x=797,y=239)
        self.btnPlay = Button(self.root,text="PLAY AUDIO",width=36,height=2,bg="gray70",command=self.init_task2)
        self.btnPlay.place(x=650,y=53)#.place(x=650,y=301)
        Button(self.root,text="REVERSE AUDIO",width=35,height=2,bg="light green",command=self.reverse_audio).place(x=12,y=177)
        Button(self.root,text="CLEAR CHANGES",width=35,height=2,bg="light green",command=self.clear_changes).place(x=12,y=239)
        Button(self.root,text="HISTORY",width=35,height=2,bg="light green",command=self.show_history).place(x=12,y=301)
        self.stateLabel = Label(self.root,text="",width=86,bg="gray28",fg="light blue")
        self.stateLabel.place(x=14,y=148)
        self.slider = Scale(self.root,length=130,bg="gray25",fg="white",from_=2.00, to=0.01, digits = 3, resolution = 0.01)
        self.slider.set(1.00)
        self.slider.place(x=290,y=207)
        Label(self.root,text="SPEED",fg="white",bg="gray28").place(x=295,y=180)
        self.slider1 = Scale(self.root,length=130,bg="gray25",fg="white",from_=50, to=-50)
        self.slider1.set(1)
        self.slider1.place(x=360,y=207)
        Label(self.root,text="VOLUME",fg="white",bg="gray28").place(x=357,y=180)
        self.slider2 = Scale(self.root,length=130,bg="gray25",fg="white",from_=50, to=1)
        self.slider2.place(x=437,y=207)
        Label(self.root,text="GAIN",fg="white",bg="gray28").place(x=438,y=180)
        self.slider3 = Scale(self.root,bg="gray25",fg="white",length=130, from_=1000, to=1)
        self.slider3.place(x=510,y=207)
        Label(self.root,text="FADE IN",fg="white",bg="gray28").place(x=505,y=180)
        self.slider4 = Scale(self.root,bg="gray25",fg="white",length=130, from_=1000, to=1)
        self.slider4.place(x=580,y=207)
        Label(self.root,text="FADE OUT",fg="white",bg="gray28").place(x=570,y=180)
 
        self.root.mainloop()
 
    def open_file(self):
        self.stateLabel.configure(text="")
        self.audio_file = filedialog.askopenfilename(initialdir = "/",
                     title="Select audio",filetypes = (("mp3 files","*.mp3"),
                     ("wav files","*.wav"),("ogg files","*.ogg"),
                     ("flv files","*.flv"),("mp4 files","*.mp4")))
        if self.audio_file != "":
            self.audio_f = (self.audio_file.split("/"))[-1]
            self.name,self.ex = os.path.splitext(self.audio_f)
            self.audioName.set(self.audio_f)
            self.import_audio()
 
    def change_audio_characts(self,mode):
        self.stateLabel.configure(text="")
        speed = self.slider.get()
        if mode == "save":
            self.audio = (self.audio._spawn(self.audio.raw_data, overrides={"frame_rate": int(self.audio.frame_rate * speed)})).fade_out(self.slider4.get()).fade_in(self.slider3.get()
                        ).apply_gain(self.slider2.get())+self.slider1.get()
        else:
            self.prev_audio = (self.audio._spawn(self.audio.raw_data, overrides={"frame_rate": int(self.audio.frame_rate * speed)})).fade_out(self.slider4.get()).fade_in(self.slider3.get()
                        ).apply_gain(self.slider2.get())+self.slider1.get()
 
 
        return (self.audio.set_frame_rate(self.audio.frame_rate))
 
    def play_audio(self):
        if self.audio != "":
            if "preview.wav" in os.listdir():
                mixer.music.unload()
                os.remove("preview.wav")
            self.stateLabel.configure(text="PLAYING")
            self.change_audio_characts("display")
            self.prev_audio.export("preview.wav",format="wav")
            pos_time = mixer.music.get_pos()
            mixer.music.load("preview.wav")
            mixer.music.play()
            self.update_state()
            self.history = self.history+("---->PLAYED PREVIEW AUDIO.\n")
 
    def update_state(self):
        pos_time = mixer.music.get_pos()
        if pos_time != -1:
            self.btnPlay.configure(text="STOP AUDIO")
            self.btnPlay.configure(command=self.stop_audio)
            print("PLAYING")
            self.root.after(500, self.update_state)
        else:
            print("NOT PLAYING")
            self.btnPlay.configure(text="PLAY AUDIO")
            self.btnPlay.configure(command=self.play_audio)
            self.root.after_cancel(self.update_state)
            #mixer.quit()
 
    def stop_audio(self):
         mixer.music.stop()
         self.btnPlay.configure(text="PLAY AUDIO")
         self.btnPlay.configure(command=self.play_audio)
 
 
    def init_task2(self):
        t = threading.Thread(target=self.play_audio)
        t.start()
 
    def show_history(self):
        if self.history != "":
            top = Toplevel()
            top.title("EDITION HISTORY")
            self.display = sct.ScrolledText(master=top,width=90,height=30,bg="gray91")
            self.display.pack(padx=0,pady=0)
            self.display.insert(END,self.history)
            Button(top,text="CLEAR HISTORY",bg="gray70",command=self.clear_history).pack(side=BOTTOM)
 
    def clear_history(self):
        self.display.delete('1.0',END)
 
    def clear_changes(self):
        if self.audio != "":
            self.audio = self.original_audio
            self.slider.set(1.00)
            self.slider2.set(1)
            self.slider4.set(1)
            self.slider3.set(1)
            self.slider1.set(1)
            self.stateLabel.configure(text="RESTORED ORIGINAL AUDIO")
 
            self.history = self.history+("---->RESTORED ORIGINAL AUDIO.\n")
 
    def init_task(self,ex):
        if self.audio != "":
            self.extension = ex
            t = threading.Thread(target=self.export_audio)
            t.start()
 
    def reverse_audio(self):
        if self.audio != "":
            try:
                self.audio = self.audio.reverse()
                self.history=self.history+"---->AUDIO REVERSED.\n"
                self.stateLabel.configure(text="REVERSED")
            except Exception as e:
                messagebox.showwarning("UNEXPECTED ERROR",str(e))
                self.history = self.history+("---->UNEXPECTED ERROR: {}.".format(str(e)))+"\n"
 
    def export_audio(self):
        self.stateLabel.configure(text="SAVING FILE")
        try:
            self.change_audio_characts("save")
            self.history = self.history+"---->APPLIED AUDIO CHARACTS.\n"
            file = filedialog.asksaveasfilename(initialdir="/",initialfile=self.name,
                    title="SAVE AS",defaultextension="."+self.extension)
            if file != "":
                self.audio.export(file,format=self.extension)
                file_saved = (file).split("/")[-1]
                messagebox.showinfo("SAVED FILE","Saved file as: {}.".format(file_saved))
                self.history = self.history+("---->SAVED FILE AS: {}.".format(file_saved))+"\n"
        except Exception as e:
            messagebox.showwarning("UNEXPECTED ERROR",str(e))
            self.history=self.history+"---->UNEXPECTED ERROR: {}\n".format(str(e))
 
        self.stateLabel.configure(text="")
 
    def import_audio(self):
        try:
            if self.ex == ".mp3":
                self.audio = AudioSegment.from_mp3(self.audio_file)
            elif self.ex == ".wav":
                self.audio = AudioSegment.from_wav(self.audio_file)
            elif self.ex == ".ogg":
                self.audio = AudioSegment.from_ogg(self.audio_file)
            elif self.ex == ".flv":
                self.audio = AudioSegment.from_flv(self.audio_file)
            else:
                self.audio = AudioSegment.from_file(self.audio_file)
            self.history = self.history+("\n-->LOADED: {}.".format(self.audio_f))+"\n"
            self.original_audio = self.audio
        except Exception as e:
            messagebox.showwarning("UNEXPECTED ERROR",str(e))
            self.history = self.history+("---->UNEXPECTED ERROR: {}.".format(str(e)))+"\n"
            self.audio = ""
 
if __name__=="__main__":
    editor()



Comentarios sobre la versión: 0.1 (0)


No hay comentarios
 

Comentar la versión: 0.1

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s7166