Customizing Label Export

Audio software developers forum.

If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like

Customizing Label Export

Permanent link to this post Posted by Muxson » Tue Feb 13, 2018 4:36 am

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
Label Example.png (9.14 KiB) Viewed 226 times

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:
Code: Select all
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:
Code: Select all
[VoicePrompt]
FileName=Chap. 18.mp3
PromptStart=0.201864
PromptStop=2.079199


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... ;)

Thanks for your consideration.
Muxson
Muxson
 
Posts: 5
Joined: Mon Feb 12, 2018 5:10 am
Operating System: Windows 10

Re: Customizing Label Export

Permanent link to this post Posted by steve » Tue Feb 13, 2018 1:55 pm

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.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45989
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Customizing Label Export

Permanent link to this post Posted by Edgar » Tue Feb 13, 2018 4:02 pm

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.
-Edgar
compiling Audacity daily
64-bit Windows 7
Edgar
Forum Crew
 
Posts: 1496
Joined: Thu Sep 03, 2009 9:13 pm
Operating System: Windows 7

Re: Customizing Label Export

Permanent link to this post Posted by Muxson » Wed Feb 14, 2018 12:34 am

Thanks Steve!
Yes, that is one option. I'm using AutoIt for this king of things. Here is an example of what I did: http://www.muxson.com/winloud.
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?
Muxson
 
Posts: 5
Joined: Mon Feb 12, 2018 5:10 am
Operating System: Windows 10

Re: Customizing Label Export

Permanent link to this post Posted by steve » Wed Feb 14, 2018 1:52 am

Muxson wrote:the exported file be called after the audio track name (audio file name)

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).

Muxson wrote:the exported file extension be .vp (not .txt)

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?

Muxson wrote:the exported file be created in the same folder like the audio file

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

Muxson wrote:the data be structured as name:value pairs (like in a .ini file)

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.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45989
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Customizing Label Export

Permanent link to this post Posted by Muxson » Wed Feb 14, 2018 2:54 am

Nice, all your suggestions are workable, Steve.

steve wrote:It would be possible to make a plug-in that adds the audio track name to the label.

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?

steve wrote:This would require running the plug-in "effect" to create the label

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

steve wrote: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?

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

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

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

Muxson wrote: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.

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...)?
Muxson
 
Posts: 5
Joined: Mon Feb 12, 2018 5:10 am
Operating System: Windows 10

Re: Customizing Label Export

Permanent link to this post Posted by steve » Wed Feb 14, 2018 4:04 am

Muxson wrote:Pulling the track name automatically would be a great time-saver, for sure.

This is the code to create a label at the current selection, using the selected track name as the label text:
Code: Select all
(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: http://wiki.audacityteam.org/wiki/Nyqui ... -in_Header)

Muxson wrote:Would it be possible to use it automatically as the filename?

No, because the file name is created when you export the labels, and that's all coded into Audacity.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45989
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Customizing Label Export

Permanent link to this post Posted by Muxson » Wed Feb 14, 2018 9:48 pm

Wow, that's all it takes?
Thanks you Steve, I will try it as soon as I can.
Muxson
 
Posts: 5
Joined: Mon Feb 12, 2018 5:10 am
Operating System: Windows 10

Re: Customizing Label Export

Permanent link to this post Posted by Muxson » Fri Feb 16, 2018 8:03 pm

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.

Muxson
Muxson
 
Posts: 5
Joined: Mon Feb 12, 2018 5:10 am
Operating System: Windows 10


Return to General Audio Programming



Who is online

Users browsing this forum: No registered users and 2 guests