How to import .wav file using mod-script-pipe


Today (not without adventures :wink:), I managed to build Audacity 2.3.3 with mod-script-pipe.

But I cannot find a way to import .wav file into audacity via script.
Examples like this (which among other things import wav file):

are no longer up-to-date I’m afraid.

Command Import Audio unfortunately has no parameter available and opens dialog window.
Manual (Scripting Reference - Audacity Manual) says that:

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”:


Thanks Steve, it worked!

I thought maybe someone will need some updated example on how to batch process many files so I will paste it here (much of the code is copied from:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import errno
import fnmatch
import os
import sys
import tempfile

if sys.platform == 'win32':
    print("Load and save wave test, running on windows")
    toname = '\\\\.\\pipe\\ToSrvPipe'
    fromname = '\\\\.\\pipe\\FromSrvPipe'
    EOL = '\r\n\0'
    print("Load and save wave test, running on linux or mac")
    toname = '/tmp/' + 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.")

print("Read from \"" + fromname + "\"")
if not os.path.exists(fromname):
    print(" ..does not exist.  Ensure Audacity is running with mod-script-pipe.")

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)

def get_response():
    result = ''
    line = ''
    while line != '\n' :
        result += line
        line = fromfile.readline()

    return result

def do_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)

def remove_selected_track():

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)
                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)
    except OSError as e:
        if e.errno != errno.EEXIST:

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)
        paul_stretch_track(20, 0.5)

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

Thank you for sharing your Script.
I would suggest that an easier approach might be:

import pipeclient