Macros and Scripting

It would be nice to have a macro for ImportLabelFile, and it would also be nice to have parameters for file operations in Mo-Script-Pipe scripts rather than just opening a dialog.
To explain in more detail (skip this if bored). I needed to automate importing a .wav file and its associated .txt label file, automatically from my own application and then to zoom and pan to specific location in the file. A straightforward enough task.
Originally I did this by using a inputSimulator to simulate keystrokes into Audacity, but the problem with this approach is that you get no feedback on when a command has completed so that you have to put in time delays adequate for the slowest computer it might run on. Not ideal but it works.
The I tried to do the task with Macros, but there is no macro for ImportLabelTrack, so this had to be done with keyboard simlator as before and since it follows the long running audio file load (200kB files - 4-5 minutes at 384000sps) it didnt help a lot, but does make the zooming and panning better.
I tried using mod-script-pipe, opening a named pipe from my program, which works nicely and has feedback so that you know when a task has completed and can then send the enxt command. However ImportFile and ImportLabelTrack bot open a user dialog to select the file manually. I do use this, but then have to resort to the keybaord simulator again to enter the filenames, so this si till not an ideal solution.
In short it seems that ImportlabelTrack should be available as a amcro, but has simply been overlooked.
Mod-script-pipes is still experimental I gather and has parameterization for some command, but it would be nice to see that parameterization extended to other commands that result in a user dialog - which rather obviates the purpose of automation.

If you are using mod-script-pipe, you can fairly easily read a label text file with your scripting language, then create the labels according to that data.
Alternatively you could create a Nyquist plug-in to read a label text file and create a label track.

Import2: allows you to specify the file to import. The file name should be “fully qualified” (includes the full path to the file, the file name, and the file extension).
Import2 only works with recognized audio files, not label track files.

Be careful with this. Often you do not know when a task has completed. What you know is when the command has been executed, which is not necessarily when it has completed.

A good example to demonstrate the difference is the “Play” command. If you send a Play command from Python via mod-script-pipe, then the command will execute very quickly and return an “OK” reply almost straight away, while playback continues until either you tell it to stop, or playback reaches the end of the selection.

For example:
importlabels.ny (517 Bytes)
You can of course modify the “;control” line to set your own default label track file name.
When used from Python you would pass the file name as a parameter.

Steve, thankyou for your prompt and informative reply, and also for the Nyquist file which I will try. I am aware that some commands will return before the execution is completed as you point out, but with the keyboard simulator the problem occurring was that following commands would disappear and never be acted upon. I think, and at least for the commands I am using, that once I get the response following commands will be received and acted upon. I just have to be a little careful in situations where the order matters, such as creating tracks in sequence. I had also considered parsing the existing label file and adding the labels to a new label track, which remains a possibility if I still have problems on slower machines, but it does seem a bit of a kludge, especially when there are a lot of labels. :slight_smile:

Try the Nyquist plug-in. It should be very fast.
Let me know how it goes :wink:

Sorry Steve, I am probably overlooking something terribly obvious, but I just can’t get it to work.
I have installed the .ny file as a plug-in and it appears in the generate menu. When I run that it gives a dialog asking for a file name, which I enter but then nothing happens. I have tried enterig the filename with single, double or even quadruple backslashes but still no joy.
I have tried to run it from a Macro. When I create the macro (through the tools menu) the Edit Parameters button prompts for a ‘Label Track File’, but when the macro is created the macro parameters appear as:- Command=“” Version=“4”
When I look to activate it through a Mod-Scrip-Pipe I can’t see any way of running a Nyquist command with a filename parameter. Nyquistprompt takes a ‘Command’ parameter, but It is not clear how the filename could be embedded into that.
For now at least, using the named Pipe to call ImportLabels: and using the keyboard simulator to enter the filename seems to work adequately.
Thanks for your efforts anyway.

When using the plug-in’s GUI, file names should not be quoted.
I’ve not checked on Windows, but I think that either single forward slash “/” or back slash "" can be used as the file separator.

The file name must be a "fully qualified filename. On Windows that means that it starts with a drive letter (such as "C:") and ends with the file extension “.txt”

Try clicking the “Debug” button rather than the “OK” button. In the event of an error, the error message will be displayed.

Note that the label text file must NOT have frequency selections. It must only have the start / end times and label text.

Once we have this plug-in working from the GUI, we will move on to running it in a Macro, but let’s deal with the basics first :wink: