Commit fa9944b7 authored by Matteo's avatar Matteo
Browse files

update script

parent f03789ef
.idea .idea
.DS_Store .DS_Store
data/
# Working path # Working path
WORKING_PATH: "/Users/nadir/Documents/MPAI-CAE/Workflow" WORKING_PATH: "./data"
# Name of the Preservation Audio File (without extension) # Name of the Preservation Audio File (without extension)
FILES_NAME: "sample12_W7N_R15C" FILES_NAME: "sample12_W7N_R15C"
# PRESERVATION_FILE_NAME: "BornToDie" # PRESERVATION_FILE_NAME: "BornToDie"
......
'''
Script to run tapeAudioRestoration.py on all files in a directory
Author: Matteo Spanio
Date: 2023-053-28
Usage:
python script.py -i <input_directory> -o <output_directory>
the -o argument is optional, if not specified the script will use the WORKING_PATH variable in config.yaml
the -i argument is mandatory
the speed and standard values are taken from config.yaml
Description:
Given a directory containing all the files to be processed, the script will create a folder structure in the output directory
containing the original files in the PreservationAudioFile folder and the output of the tapeAudioRestoration.py script in the
RestoredAudioFiles folder. The output folder will contain all the files with the same name as the original files.
'''
import os import os
import subprocess import subprocess
import shutil
import yaml
import argparse
def create_folder_structure(destination, file_names, original_files):
if os.path.exists(destination):
shutil.rmtree(destination)
os.makedirs(os.path.join(destination, "PreservationAudioFile"))
for name in file_names:
os.makedirs(os.path.join(destination, "temp", name))
for file in original_files:
shutil.copy(os.path.join(file), os.path.join(destination, "PreservationAudioFile"))
def get_files_name(input_dir):
file_names = []
for filename in os.listdir(input_dir):
if filename.endswith(".wav"):
file_names.append(filename.split(".")[0])
return file_names
INPUT_DIR = "./" def read_config():
with open("config.yaml", 'r') as stream:
try:
config = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
return config
config = {
"file_names": os.listdir(INPUT_DIR), def main():
"w_eq_standard": "NAB", parser = argparse.ArgumentParser(description="Script to run tapeAudioRestoration.py on all files in a directory")
"r_eq_standard": "CCIR", parser.add_argument("-i", "--input-directory", help="Directory containing all files to be processed", required=True)
"w_speed": "7.5", parser.add_argument("-o", "--output-directory", help="Directory to store all processed files")
"r_speed": "7.5"
} config = read_config()
args = parser.parse_args()
input_directory = os.path.abspath(args.input_directory)
output_directory = args.output_directory or config["WORKING_PATH"]
standard_w = config["STANDARD_W"]
standard_r = config["STANDARD_R"]
speed_w = str(config["SPEED_W"])
speed_r = str(config["SPEED_R"])
files_names = get_files_name(input_directory)
create_folder_structure(output_directory, files_names, [os.path.join(input_directory, x) for x in os.listdir(input_directory)])
for filename in files_names:
subprocess.run(["python3", "./tapeAudioRestoration.py", "-w", output_directory, "-f", filename, "-ew", standard_w, "-sw", speed_w, "-sr", speed_r, "-er", standard_r])
os.mkdir(os.path.join(output_directory, "RestoredAudioFiles"))
for dir in os.listdir(os.path.join(output_directory, "temp")):
shutil.move(os.path.join(output_directory, "temp", dir, "RestoredAudioFiles", "1.wav"), os.path.join(output_directory, "RestoredAudioFiles", dir + ".wav"))
shutil.rmtree(os.path.join(output_directory, "temp"))
if __name__ == '__main__': if __name__ == '__main__':
for filename in config["file_names"]:
if not os.path.exists(INPUT_DIR + "/temp"): main()
os.makedirs(INPUT_DIR + "/temp")
subprocess.run(["python3", "tapeAudioRestoration.py", "-w", INPUT_DIR, "-f", filename, "-ew", config["w_eq_standard"], "-sw", config["w_speed"], "-sr", config["r_speed"], "-er", config["r_eq_standard"]])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment