Batch Conversion of CAF files to AIFF
#!/usr/bin/env python
import os
# Set the paths
INPUT_DIR = "CHANGE TO INPUT DIRECTORY"
OUTPUT_DIR = INPUT_DIR + "/Output"
# Check to make sure the directories exist and are accessible
try:
os.chdir(INPUT_DIR)
print "Input Directory Set: " + INPUT_DIR
# Let's go and make the output directory if it's not already created
try:
os.mkdir(OUTPUT_DIR)
print "Output Directory Set: " + OUTPUT_DIR
except os.error:
try:
os.chdir(OUTPUT_DIR)
os.chdir(INPUT_DIR)
print "Output Directory Set: " + OUTPUT_DIR
except os.error:
print "Output Directory Inaccessible: " + OUTPUT_DIR
# Now let's go through and deal with all the sound files
DIRECTORY_CONTENTS = os.listdir(INPUT_DIR)
for INPUT_FILE in DIRECTORY_CONTENTS:
try:
INPUT_PATH = INPUT_DIR + "/" + INPUT_FILE
if INPUT_PATH.index(".caf") > 0:
print "Input File: " + INPUT_PATH
OUTPUT_PATH = OUTPUT_DIR + "/" + INPUT_FILE + ".aiff"
print "Output File: " + OUTPUT_PATH
COMMAND = "afconvert -f AIFF -d I8 " + INPUT_PATH + " " + OUTPUT_PATH
print "Command Call: " + COMMAND
os.system(COMMAND)
except ValueError as e:
print "Value Error: {0}".format(e)
except subprocess.CalledProcessError as e:
print "Process Error #{0}: {1}".format(e.errno, e.strerror)
except os.error as e:
print "OS Error #{0}: {1}".format(e.errno, e.strerror)
exit