#!/usr/bin/env python # -*- coding: utf-8 -*- #audacity & sleep 20 && python3 Audacity_Batch_Export.py import os import sys import psutil ######################################## #Remember the . in the extension ! export_extension = ".wav" #Slash direction (linux style / vs Windows \) path_slash_style = "/" #Note, the quotes and end , are important ! Find/Replace .aup3 with .aup3", and file:// or C:\ with # " or "C:\ etc. project_files_list= [ "/path/to/project1.aup3", "/path/to/project2.aup3", "/path/to/project3.aup3", ] ######################################### if sys.platform == 'win32': print("pipe-test.py, running on windows") TONAME = '\\\\.\\pipe\\ToSrvPipe' FROMNAME = '\\\\.\\pipe\\FromSrvPipe' EOL = '\r\n\0' if str("audacity.exe" in (i.name() for i in psutil.process_iter())) == "False": print("Audacity needs to be running first - launch it! and make sure Audacity > Edit > Preferences > Modules > Mod-Script-Pipe is Enabled.") quit() else: print("pipe-test.py, running on linux or mac") TONAME = '/tmp/audacity_script_pipe.to.' + str(os.getuid()) FROMNAME = '/tmp/audacity_script_pipe.from.' + str(os.getuid()) EOL = '\n' if str("audacity" in (i.name() for i in psutil.process_iter())) == "False": print("Audacity needs to be running first - launch it! and make sure Audacity > Edit > Preferences > Modules > Mod-Script-Pipe is Enabled.") quit() TOFILE = open(TONAME, 'w') FROMFILE = open(FROMNAME, 'rt') def send_command(command): TOFILE.write(command + EOL) TOFILE.flush() def get_response(): result = '' line = '' while True: result += line line = FROMFILE.readline() if line == '\n' and len(result) > 0: break return result def do_command(command): send_command(command) response = get_response() print("Rcvd: <<< \n" + response) return response for project_file_path in project_files_list: #Split our project file path down and create our export audio path from it. path = os.path.split(project_file_path) filename = str(path[1]) filename = filename.split(".") filename = str(filename[0]) filename = filename+export_extension #Create the export path. export_path = str(path[0]+path_slash_style+"Export"+path_slash_style+filename) #Make sure we have an export folder. try: os.mkdir(str(path[0]+path_slash_style+"Export"+path_slash_style)) except Exception as e: print(f"An error occurred: {e}") #Now open our project. open_command_prefix = "OpenProject2: Filename=\"" open_command_path = str(project_file_path) open_command_suffix = "\"" #Combine our three strings together to create the final export command. open_command_final=open_command_prefix+open_command_path+open_command_suffix #Open the current array item project in Audacity. do_command(open_command_final) #Required for export to some filetypes (e.g. mp3). do_command('SelectAll:') #Now export. export_command_prefix = "Export2: Filename=\"" export_command_suffix = "\"" #Combine our three strings together to create the final export command. export_command_final=export_command_prefix+export_path+export_command_suffix #Export the project to the desired output format. do_command(export_command_final) #Close the project, both this and the out of the loop Exit: crashes Audacity. #do_command('Close:') #Close the program #do_command('Exit:')