ImportLabels does not accept file name

audacity 3.0.2 Windows 10, version 1909, Anaconda python 3.8

I just stumbled on the scripting interface and tried to use it to load audio + tracks.
The audio loads fine, but for the tracks a selection window pops up.
How can I import labels programmatically from a file, without the modal UI step?

def quick_test():
“”“Example list of commands.”“”
do_command(‘Import2: Filename=c:/tmp/bassline.wav’)
do_command(‘ImportLabels: Filename=c:/bin/test.txt’)

In case this needs coding, we are willing to invest into learning the code, and “give back to the community” but need some guidance to get started.
Just FYI, our ultimate goal is to “drive” audacity from Excel.


I don’t see where “does not accept file name” comes into the issue :confused:

“not accept” is probably the wrong terminology, the do_command does not fail on the file name for the label track, but the filename is completely ignored. So it’s really pointless to specify a file name. I’ll be more precise when posting my next questions :sunglasses:
If I want to change this in the source code, i.e. I need similar behavior to Import2, which both “accepts” a Filename and then actually displays it. Where should I start looking?

I have some follow-up questions, for example the named pipe frequently fails, or why not use sockets or something really modern like gRPC (which would then allow access across OS with oauth2). Dear Admin, I suppose I should file those in different thread?

OK, I think I understand.
Yes you’re correct, the “ImportLabels:” command does not take any arguments (no parameters). As it says in the manual, ImportLabels: “Launches a file selection window where you can choose to import a single text file into the project containing point or region labels.

What you want is a new command “ImportLabels2:” that works in the same way as “Import2:”
Is that right?

There are currently two simple options available (and some more complex options):

Option 1, using scripting commands only:
Read the label times with your “driving application” and add the labels (one at a time) with “AddLabel:”
Add all of the (empty) labels first.
Then read the label text with your “driving application” and set the name of each label (one at a time) with “SetLabel:”

Option 2, using a Nyquist plug-in
There’s a plug-in here that can import a label text file:
Install and enable the plug-in, then send a command from your “driving application” to run the effect, with something like:


Instructions for installing Nyquist plug-ins: