You can of course use the nyquist prompt for the import and export things (and actually everything inbetween…)
The main functions are ‘s-read’ and ‘s-save’ (or ‘s-overwrite’).
Here’s the exemplary ‘s-read’ description:
LISP-syntax for this Function (316/358):
(S-READ FILENAME &KEY (TIME-OFFSET 0) (SRATE *SOUND-SRATE*) (DUR 10000) (NCHANS 1) (FORMAT *DEFAULT-SF-FORMAT*) (MODE *DEFAULT-SF-MODE*) (BITS *DEFAULT-SF-BITS*) (ENDIAN NIL))
Category: Sound File Input and Output, as found in : Fileio.Lsp
Reads a sound from a file. If a header is detected, the header is used to determine the format of the file, and header information overrides format information provided by keywords (except for :time-offset and :dur).
(s-read >mysound.snd< :srate 44100)
specifies a sample rate of 44100 hz, but if the file has a header specifying 22050 hz, the resulting sample rate will be 22050. The parameters are:
:time-offset - the amount of time (in seconds) to skip from the beginning of the file. The default is 0.0.
:srate - the sample rate of the samples in the file. Default is *default-sf-srate* , which is normally 44100.
:dur - the maximum duration in seconds to read. Default is 10000.
:nchans - the number of channels to read. It is assumed that samples from each channel are interleaved. Default is 1.
:format - the header format. See s-save for details. Default is *default-sf-format*, although this parameter is currently ignored.
:mode - the sample representation, e.g. PCM or float. See s-save for details. Default is *default-sf-format*.
:bits - the number of bits per sample. See s-save for details. Default is *default-sf-bits*.
:swap - (T or NIL) swap byte order of each sample. Default is NIL.
If there is an error, for example if :time-offset is greater than the length of the file, then NIL is returned rather than a sound. Information about the sound is also returned by s-read through *rslt*. The list assigned to *rslt* is of the form: (format channels mode bits samplerate duration flags byte-offset), which are defined as follows:
Format - the header format. See s-save for details.
channels - the number of channels.
mode - the sample representation, e.g. PCM or float. See s-save for details.
bits - the number of bits per sample.
samplerate - the sample rate, expressed as a FLONUM.
duration - the duration of the sound, in seconds.
flags - The values for format, channels, mode, bits, samplerate, and duration are initially just the values passed in as parameters or default values to s-read. If a value is actually read from the sound file header, a flag is set. The flags are: snd-head-format, snd-head-channels, snd-head-mode, snd-head-bits, snd-head-srate, and snd-head-dur. For example,
(let ((flags (caddr (cddddr *rslt*))))
(not (zerop (logand flags snd-head-srate))))
tells whether the sample rate was specified in the file. See also sf-info below.
byte-offset - the byte offset into the file of the first sample to be read (this is used by the s-overwrite and s-add-to functions).
‘s-save’ has as first parameter a sound, followed by the number of samples to be written (we use ny:all for a infinite number, i.e. a giga samples)
The rest is similar
As you might have realized, the filename has to be explicit such as: “C:\myclips\clip001.wav”
However, you can put all the filenames of a specific directory into a list and work them thru one by one.
This prints the c: directory to the debug-screen (after copying the code into the nyquist prompt and pressing debug):
(print (listdir "c:"))
In pseudo code the reading and writing would be something like this:
(psetq indir "c:\myclips\"
(dolist (file (listdir indir))
(s-read (strcat indir file) <import-options>); this statement is the read sound
ny:all (length in samples)
(strcat outdir file) <export-options>))
(It becomes messy if you want to manually edit those files, i.e. return them to Audacity as individual tracks.)
The approach over the nyquist prompt (or a Nyquist plug-in) should be straightforward.
Note that nyquist can only work with lossless files such as *.wav or *.aiff.