-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwavtoflac.py
28 lines (26 loc) · 1.15 KB
/
wavtoflac.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
import os
import argparse
from pydub import AudioSegment
def convert():
formats_to_convert = ['.wav']
mydir = os.getcwd() + "/chunks/wav"
projDir = os.getcwd()
for (dirpath, dirnames, filenames) in os.walk(mydir):
for filename in filenames:
if filename.endswith('.wav'):
fpath = dirpath + '/' + filename
(fpath, file_extension) = os.path.splitext(fpath)
ext = file_extension.replace('.', '')
try:
track = AudioSegment.from_file(str(fpath+"."+ext))
flac_filename = filename.replace(ext, 'flac')
os.chdir(mydir)
os.system(("ffmpeg -i " + filename+ " -ac 1 " + flac_filename))
os.chdir(projDir+"//chunks")
os.remove(mydir+"//"+str(filename))
os.system(("cp -f "+ mydir+"//"+flac_filename + " " + projDir + "//chunks//flac/"))
os.remove(mydir+"//"+str(flac_filename))
except:
print("Something went wrong with converting " + str(fpath))
exit(3)
os.chdir(projDir)