Export labels into a custom text file

Questions, discussion and recipes for scripting and batch processing in Audacity.
See also the "Scripting" section of the Audacity manual.
Forum rules
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
Post Reply
jmarti856
Posts: 1
Joined: Mon Nov 15, 2021 6:14 pm
Operating System: Windows 10

Export labels into a custom text file

Post by jmarti856 » Mon Nov 15, 2021 6:23 pm

Hello!
I'm new in this forum, not sure if this is the correct section to write this.
I'm a very beginner programmer, and I would like to make a "simple" exporter to export the labels of an audio into a custom text file.
The text file format is very simple:

Code: Select all

Markers
{
    Marker
    {
        Name="Label name"
        Pos="Position in samples"
    }
    Marker
    {
        Name="Label name"
        Pos="Position in samples"
    }
}
The idea is to create a "Marker" block for each sample. I have some questions about it.
1 - Is possible to create an exporter to do this?
2 - How should I start? Could be done in python?

Thanks!

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

Re: Export labels into a custom text file

Post by steve » Tue Nov 16, 2021 12:53 am

jmarti856 wrote:
Mon Nov 15, 2021 6:23 pm
Could be done in python?
Using Audacity's scripting module, you can issue the command "GetInfo: Type=Labels" which will return the labels formatted as a JSON string like this:

Code: Select all

[ 
  [ 1,
    [ 
      [ 0.0590437, 0.0590437, "Label one" ],
      [ 0.508684, 0.508684, "Label 2" ],
      [ 0.920476, 1.03554, "Region label" ] ] ] ]
(The "1" on the second line indicates the track number)

You can find some information about scripting in Audacity here: https://manual.audacityteam.org/man/scripting.html
Learn more about Nyquist programming at audionyq.com

Post Reply