ImportLabels does not accept file name

Help for Audacity on Windows.
Forum rules
ImageThis forum is for Audacity on Windows.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".


Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
Post Reply
hsinger
Posts: 3
Joined: Sat May 08, 2021 8:04 pm
Operating System: Windows 10

ImportLabels does not accept file name

Post by hsinger » Mon May 10, 2021 9:52 pm

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')
do_command('PlayStop:')
...

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.

thanks

steve
Site Admin
Posts: 81421
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: ImportLabels does not accept file name

Post by steve » Tue May 11, 2021 8:46 am

I don't see where "does not accept file name" comes into the issue :?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

hsinger
Posts: 3
Joined: Sat May 08, 2021 8:04 pm
Operating System: Windows 10

Re: ImportLabels does not accept file name

Post by hsinger » Wed May 12, 2021 10:26 am

"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 8-)
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?

steve
Site Admin
Posts: 81421
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: ImportLabels does not accept file name

Post by steve » Wed May 12, 2021 11:10 am

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: viewtopic.php?p=396368#p396368
Install and enable the plug-in, then send a command from your "driving application" to run the effect, with something like:

Code: Select all

do_command('ImportLabels:fname="c:/bin/test.txt"')
Instructions for installing Nyquist plug-ins: https://manual.audacityteam.org/man/ins ... st_install
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply