code to explanationThu, 12 Jan 2023

import os import subprocess from send2trash import send2trash import time def convert_to_16bit_44khz(filepath): filename = os.path.basename(filepath) wav_file_name = os.path.splitext(filename)[0] + ".wav" new_file_name = os.path.splitext(filename)[0] + "-converted.flac" try: output = subprocess.run(["flac", "-d", filepath], capture_output=True, text=True) if "ERROR" in output.stderr: print("An error occurred: " + output.stderr) else: subprocess.run(["sox", wav_file_name, "-b", "16", "-r", "44100", "-e", "signed", wav_file_name]) subprocess.run(["flac", wav_file_name, "-f", "--delete-input-file"]) os.rename(wav_file_name + ".flac", new_file_name) print(f"Converted {filename} to {new_file_name}") send2trash(filepath) except: print("An error occurred while converting " + filename) time.sleep(15) for subdir, dirs, files in os.walk("d:\\lidarr"): for file in files: if file.endswith(".flac"): filepath = subdir + os.sep + file convert_to_16bit_44khz(filepath)

This script walks through all subdirectories of d:\lidarr and looks for each file ending with .flac. For each of these files it starts the conversion process.

Want to kickstart your project?Use the new AI Studio to create your code