-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathvid_to_wav.py
44 lines (40 loc) · 1.81 KB
/
vid_to_wav.py
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
import subprocess
import os
import zipfile
## Runnin a loop throught all the zipped training file to extract all .wav audio files
for i in range(1,76):
if i<10:
zipfilename = 'training80_0'+str(i)+'.zip'
else:
zipfilename = 'training80_'+str(i)+'.zip'
## Accessing the zipfile i
archive = zipfile.ZipFile('data/'+zipfilename, 'r')
zipfilename = zipfilename.split('.zip')[0]
#archive.extractall('unzippedData/'+zipfilename)
for file_name in archive.namelist():
file_name=(file_name.split('.mp4'))[0]
try:
if not os.path.exists('VoiceData/trainingData/'):
os.makedirs('VoiceData/trainingData/')
except OSError:
print ('Error: Creating directory of data')
command = "ffmpeg -i unzippedData/{}/{}.mp4 -ab 320k -ac 2 -ar 44100 -vn VoiceData/trainingData/{}.wav".format(zipfilename,file_name,file_name)
subprocess.call(command, shell=True)
for i in range(1,26):
if i<10:
zipfilename = 'validation80_0'+str(i)+'.zip'
else:
zipfilename = 'validation80_'+str(i)+'.zip'
## Accessing the zipfile i
archive = zipfile.ZipFile('data/'+zipfilename, 'r')
zipfilename = zipfilename.split('.zip')[0]
#archive.extractall('unzippedData/'+zipfilename)
for file_name in archive.namelist():
file_name=(file_name.split('.mp4'))[0]
try:
if not os.path.exists('VoiceData/validationData/'):
os.makedirs('VoiceData/validationData/')
except OSError:
print ('Error: Creating directory of data')
command = "ffmpeg -i unzippedData/{}/{}.mp4 -ab 320k -ac 2 -ar 44100 -vn VoiceData/validationData/{}.wav".format(zipfilename,file_name,file_name)
subprocess.call(command, shell=True)