Re: Adding random noise in the entire directory that contains audio files
Posted: Thu Dec 10, 2020 11:13 am
I've just noticed that the script that I wrote assumes no spaces in the file names.
If your file names (or file paths) have spaces, then the Filenames need to be quoted in the "client.write" strings:
If your file names (or file paths) have spaces, then the Filenames need to be quoted in the "client.write" strings:
Code: Select all
#!/usr/bin/env python3
import os
from random import choice
import pipeclient as pc
IN_DIR = r"/home/steve/Desktop/temp/folder_in"
OUT_DIR = r"/home/steve/Desktop/temp/folder_out"
NOISE_DIR = r"/home/steve/Desktop/temp/folder_noise"
def process():
client = pc.PipeClient()
for file in os.listdir(IN_DIR):
sound = os.path.join(IN_DIR, file)
noise = os.path.join(NOISE_DIR, choice(os.listdir(NOISE_DIR)))
output = os.path.join(OUT_DIR, file)
client.write(f'Import2: Filename="{sound}"')
client.write(f'Import2: Filename="{noise}"')
client.write('SelectAll:')
client.write('MixAndRender:')
client.write('Normalize: PeakLevel=-1 ApplyGain=1')
client.write(f'Export2: Filename="{output}"')
client.write('RemoveTracks:')
client.read()
if __name__ == '__main__':
process()