directory = ""

rate = 48000

depth = 16

"""
Explanation: Convert WAV sampling rate and bit depth
This notebook converts WAV files in the specified 'directory' into FLAC format with the specified sampling 'rate' and bit 'depth'.
Variable definitions
directory – directory containing WAV files <br />
rate – sampling rate (Hertz) <br />
depth – bit depth (bits)
End of explanation
"""


import subprocess
import os.path
from os import listdir

"""
Explanation: Import packages
End of explanation
"""


os.chdir(directory)
os.chdir(os.pardir)
converted_directory = os.path.abspath(os.curdir) + '/converted'
if os.path.exists(converted_directory):
    os.rmdir(converted_directory)
os.mkdir(converted_directory)

"""
Explanation: Set directory
End of explanation
"""


WAV_files = [f for f in listdir(directory) if os.path.isfile(os.path.join(directory, f)) and f.split('.')[1] == 'WAV']

"""
Explanation: Find all WAV files in directory
End of explanation
"""


for filename in WAV_files:
    infilename = './clipped/' + filename
    outfilename = './converted/' + filename
    subprocess.check_output(["sox", infilename, "-r", str(rate), "-b", str(depth), outfilename])

"""
Explanation: Convert all WAV files in directory
End of explanation
"""


for filename in WAV_files:
    infilename = './converted/' + filename
    subprocess.check_output(["flac", infilename])

"""
Explanation: Convert all WAV files in directory to flac files
End of explanation
"""


