Actions that end with ‘…’ and have “Parameters none” listed will pop up a dialog during the script to get the paramters, and are not properly supported by scripting. Use at your own risk.
Do you know of some workaround? I have like 2k small files and want to batch process them using some of the effects (e.g. PaulStretching).
Does the scripting command “Import” (“Import2”) from the “Extra menu > Scriptables II” work for you?
Note that you have to use a fully qualified file name, for example, to import a file “file-name.wav” from the Desktop of a user “user-name”:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import errno
import fnmatch
import os
import sys
import tempfile
# INITIALIZE READ AND WRITE PIPES
if sys.platform == 'win32':
print("Load and save wave test, running on windows")
toname = '\\\\.\\pipe\\ToSrvPipe'
fromname = '\\\\.\\pipe\\FromSrvPipe'
EOL = '\r\n\0'
else:
print("Load and save wave test, 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'
print("Write to \"" + toname + "\"")
if not os.path.exists(toname):
print(" ..does not exist. Ensure Audacity is running with mod-script-pipe.")
sys.exit()
print("Read from \"" + fromname + "\"")
if not os.path.exists(fromname):
print(" ..does not exist. Ensure Audacity is running with mod-script-pipe.")
sys.exit()
print("-- Both pipes exist. Good.")
tofile = open(toname, 'w')
print("-- File to write to has been opened")
fromfile = open(fromname, 'rt')
print("-- File to read from has now been opened too\r\n")
def send_command(command):
print( "Send: >>> "+command)
tofile.write(command + EOL)
tofile.flush()
def get_response():
result = ''
line = ''
while line != '\n' :
result += line
line = fromfile.readline()
return result
def do_command(command):
send_command(command)
response = get_response()
print("Rcvd: <<< " + response )
return response
def import_wave(input_path):
do_command("Select: Track=0")
do_command("Import2: Filename={}".format(input_path))
def export_wave(output_path):
export_command = "Export2: Filename={}".format(output_path)
do_command(export_command)
def remove_selected_track():
do_command("RemoveTracks")
def paul_stretch_track(stretch_factor, time_resolution):
do_command("Paulstretch: Stretch Factor={0} Time Resolution={1}".format(stretch_factor, time_resolution))
def change_tempo(percentage, sbsms=False):
do_command("ChangeTempo: Percentage={0} SBSMS={1}".format(percentage, sbsms))
def get_files(path, get_absolute=True, extension='wav'):
path = path.replace('\\', '/')
matches = []
for root, dirnames, filenames in os.walk(path):
for filename in fnmatch.filter(filenames, '*.' + extension):
if get_absolute:
filepath = os.path.join(root, filename)
else:
filepath = os.path.join(root[len(path) + 1:], filename)
matches.append(filepath.replace('\\', '/'))
return matches
def make_sure_dir_exists(directory, is_file_path=False):
"""
Forces creating directory if such does not exist.
:param directory: path to directory that we wish to exist
:type directory: basestring
"""
if is_file_path:
directory = os.path.dirname(directory)
try:
os.makedirs(directory)
except OSError as e:
if e.errno != errno.EEXIST:
raise
if __name__ == '__main__':
folder_with_waves = '/home/dankal/bazy/test_base'
output_folder = '/home/dankal/bazy/test_base_stretched_output'
for relative_path in get_files(folder_with_waves, get_absolute=False):
input_path = os.path.join(folder_with_waves, relative_path)
output_path = os.path.join(output_folder, relative_path)
make_sure_dir_exists(output_path, is_file_path=True)
import_wave(input_path)
paul_stretch_track(20, 0.5)
export_wave(output_path)
remove_selected_track()
PS.I had some problem with missing ChangeTempo effect, but I decided that I’ll use soundstretch directly, in command line (I assume you still use it, just for some reason it did not get installed).