I have the following Python script that should be able to convert a music file as an AIFF format. Everything works really well, however, the last function, sf.write
do not allow me to save the new file with metadata.
import os
import soundfile as sf
# Specify the input and output directories
input_dir = r"C:\Users\lillo\Desktop\Music\try"
output_dir = r"C:\Users\lillo\Desktop\Music\try"
# Loop through all files in the input directory
for filename in os.listdir(input_dir):
if filename.endswith(".wav") or filename.endswith(".flac") or filename.endswith(".flac"):
# Load the audio file and its metadata
audio, sr = sf.read(os.path.join(input_dir, filename), always_2d=True)
metadata = sf.info(os.path.join(input_dir, filename)).__dict__
# Set the output filename and path
output_filename = os.path.splitext(filename)[0] + ".aiff"
output_path = os.path.join(output_dir, output_filename)
# Write the AIFF file with the same metadata as the original file
#sf.write(output_path, audio, sr, format="AIFF", subtype="PCM_16", endian="BIG", **metadata)
sf.write(output_path, audio, sr, subtype="PCM_16", endian="BIG", format="AIFF")