Adding random noise in the entire directory that contains audio files

Help for Audacity on Windows.
Forum rules
ImageThis forum is for Audacity on Windows.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".


Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
steve
Site Admin
Posts: 80752
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Adding random noise in the entire directory that contains audio files

Post by steve » 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:

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()

9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply