Bedirhan commited on
Commit
322d295
1 Parent(s): 3e70ffd

Upload video_to_wav.py

Browse files
Files changed (1) hide show
  1. video_to_wav.py +45 -0
video_to_wav.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from moviepy.editor import AudioFileClip
2
+ import os
3
+ from keras.models import load_model
4
+ from Sound2Img import sound_2_Img
5
+ from pydub import AudioSegment
6
+ from useClahe import applyClahe
7
+
8
+
9
+ class convertWav():
10
+ def __init__(self, video_path, save_path):
11
+ self.video_path = video_path
12
+ self.save_path = save_path
13
+
14
+
15
+ def convert(self, v_path, s_path, ext):
16
+ AudioFileClip(v_path).write_audiofile(f"{s_path}.{ext}")
17
+ self.convert2Mono(s_path, ext)
18
+
19
+ def convert2Mono(self, s_path, ext):
20
+ sound = AudioSegment.from_wav(s_path + '.' + ext)
21
+ sound = sound.set_channels(1)
22
+ sound.export(s_path + '.' + ext, format="wav")
23
+
24
+ def beginn(self):
25
+ for i in os.listdir(self.video_path):
26
+ path = self.video_path + i
27
+ save_path_ = save_path + i
28
+ Ext = "wav"
29
+ self.convert(path, save_path_, Ext)
30
+
31
+
32
+ path = "Videos/tr/"
33
+ save_path = "Sounds/tr/"
34
+ converter = convertWav(path, save_path)
35
+ converter.beginn()
36
+
37
+ # model = load_model("models/CLAHE/148epochCLAHEcallback.h5")
38
+ # sound_2_Img(save_path).save_spectrograms()
39
+ # print("Spektrogram oluşturuldu!")
40
+ #
41
+ # applyClahe(save_path + 'images/').apply()
42
+ # print("Clahe uygulandı!")
43
+
44
+ # for i in os.listdir(save_path + 'images/'):
45
+ # model.predict(i)