Customizing Label Export

Hello programmers,

Can someone customize the Label Export function for me?
Or better yet, write a plugin for that purpose?

But let me start from the beginning.
I’m developing an audio book player with a special function I call “Voice Prompt”.
The idea is to play back the spoken title of the current chapter on a button press at any time while “reading” that chapter.
To do that, I need to know where that spoken titel is in the file.
One easy way I found to do it is with Audacity, specifically with Labels, as follows:
1: Select the audio section corresponding to the spoken title
2: Create makers (Ctrl + B)
3: Export Labels
Example for a file called Chap. 18.mp3:
Label Example.png
The built in Label Export function exports at text file containing the start and stop time (and name if present) of the label(s) into a file called after the Label Track Name, by default Label Track.txt. It looks like this:

0.201864 	2.079199

What I would like to have is a function or a plugin that does just a little more then that. I would like that:

  • the exported file be called after the audio track name (audio file name)
  • the exported file extension be .vp (not .txt)
  • the exported file be created in the same folder like the audio file
    And if possible, that:
  • the data be structured as name:value pairs (like in a .ini file)

A file called Chapt. 18.vp would look like this for the example above:

FileName=Chap. 18.mp3

If it was possible to make a Nyquist plugin for that custom function, it would be top.
I could then share it with different editors to “capture” and document spoken titles.
The reason I’m asking is because we have thousands of chapters and such a plugin would greatly simplify the work.

Any thoughts?

I hope I’m posting at the right place. If not, kindly let me know better… :wink:

Thanks for your consideration.

I think the easiest approach to this problem would be to write an external script, for example in Microsoft Excel, to modify the exported label files in the way that you require.

I think the easiest way would be to directly modify Audacity’s source code. Unfortunately, this would require anyone wanting to use the feature to use the modified version of Audacity. It will also mean freezing that custom version of Audacity (or updating the source code and recompiling). It would also require quite a bit of programming and testing time. Time is money and this does not look like something that a programmer would take on for free.

I have done similar modifications for a number of people and businesses. It’s not cheap and, for businesses, getting someone knowledgeable to test my modifications is not always easy.

Thanks Steve!
Yes, that is one option. I’m using AutoIt for this king of things. Here is an example of what I did:
But that would mean to (1) Export the Labels from Audacity, (2) Load the text file in another piece of software that will (if done cleverly) format the data and export it under the (3) desired name (which need to be entered or acquired somehow).
So yes, it terms of programming effort, it is probably the easiest. In term of operations, I’m not sure…

I was actually thinking of firing Audacity from my script (since it is possible to open Audacity and pass an audio file as argument in a command line) and capturing the exported file automatically but I’m not sure how easy that is…

Thanks Edgar!
I agree with you, modifying the source code is one option as well. Probably more involved then I think.
Finding a programmer to do it and then doing all the debugging is quite some work. And difficult to maintain.
That would be rather a one-off edit and live-with-it…

A plugin would be a better strategy. Is that possible at all? And would someone be willing to do it?

Any more thoughts? Anyone?

It would be possible to make a plug-in that adds the audio track name to the label.
This would require running the plug-in “effect” to create the label, rather than the usual “Ctrl + B” (though note that an effect plug-in can have a custom keyboard shortcut).

The file extension is hard coded into the Audacity code, so that would require modifying the source code and building your custom version from the modified code.
If a “.vp” file is just a plain text file with a different file extension, surely it’s not hard to modify that manually? Or can the receiving application be persuaded to accept a .txt file?

The exported folder is whatever you select in the export dialog. Plug-ins do not have access to that.

The data structure of a label file is as you see in the label text file. It has the label text, the start time and the end time (only). Modifying the data structure would require modifying the Audacity source code.

Nice, all your suggestions are workable, Steve.

Pulling the track name automatically would be a great time-saver, for sure.
If it is added to the label, it’s good. Would it be possible to use it automatically as the filename?

Perfect. And I see the user can create a custom shortcut.

A .txt extension is perfectly ok. Especially if the wished-for extension would mean a modification of the source code.

Ok. I see that the last selection is remembered even after a close down / re-start of Audacity. Good enough!

Ok, I can work with that. Again, if that means modifying the source code, it is not worth it.

It is looking good!
How much work would that be to write such a plugin (for someone with experience, not me…)?

This is the code to create a label at the current selection, using the selected track name as the label text:

(let ((start (get '*selection* 'start))
      (end (get '*selection* 'end))
      (trackname (get '*track* 'name)))
  (list (list 0 (- end start) trackname)))

To turn this into a plug-in effect, you would just need to add plug-in headers (see: Missing features - Audacity Support)

No, because the file name is created when you export the labels, and that’s all coded into Audacity.

Wow, that’s all it takes?
Thanks you Steve, I will try it as soon as I can.

Ok, I managed to get it to work.

Now I know better what the possibilities and the limitations are.

Thank you so much for taking the time.


Hey. I am not familiar with editing and creating plugins. Could you please provide indepth details or show step by step how you got the label export to work which adds names of the audio file to the labels name too?
Thank you very much.

Are you developing an audiobook player?