bitirme-proje / video_to_wav.py
Bedirhan's picture
Upload video_to_wav.py
322d295
raw
history blame
1.33 kB
from moviepy.editor import AudioFileClip
import os
from keras.models import load_model
from Sound2Img import sound_2_Img
from pydub import AudioSegment
from useClahe import applyClahe
class convertWav():
def __init__(self, video_path, save_path):
self.video_path = video_path
self.save_path = save_path
def convert(self, v_path, s_path, ext):
AudioFileClip(v_path).write_audiofile(f"{s_path}.{ext}")
self.convert2Mono(s_path, ext)
def convert2Mono(self, s_path, ext):
sound = AudioSegment.from_wav(s_path + '.' + ext)
sound = sound.set_channels(1)
sound.export(s_path + '.' + ext, format="wav")
def beginn(self):
for i in os.listdir(self.video_path):
path = self.video_path + i
save_path_ = save_path + i
Ext = "wav"
self.convert(path, save_path_, Ext)
path = "Videos/tr/"
save_path = "Sounds/tr/"
converter = convertWav(path, save_path)
converter.beginn()
# model = load_model("models/CLAHE/148epochCLAHEcallback.h5")
# sound_2_Img(save_path).save_spectrograms()
# print("Spektrogram oluşturuldu!")
#
# applyClahe(save_path + 'images/').apply()
# print("Clahe uygulandı!")
# for i in os.listdir(save_path + 'images/'):
# model.predict(i)