Convert Label text to LRC file

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.
steve
Site Admin
Posts: 80677
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Convert Label text to LRC file

Post by steve » Wed Mar 24, 2021 12:19 pm

bigboss97 wrote:
Wed Mar 24, 2021 11:13 am
I want to populate labels in a selected region. But I couldn't find any parameter in GetInfo: to retrieve the start and end of the current selection.
This is tricky in the current version of Audacity. "GetInfo:" is the only way to directly get data from Audacity back to Python, and currently there isn't a GetInfo: option to get the selection time (or even the cursor position).

You can do this with a Nyquist plug-in, but it's a bit messy.
Try this in the Nyquist Prompt:

Code: Select all

;type analyze

; get start and end times
(setf sel-start (get '*selection* 'start))
(setf sel-end (get '*selection* 'end))

;print the results
(format nil "Start = ~a   End = ~a" sel-start sel-end)

Nyquist can't delete labels, but it can create labels by returning a specially formed list.
The format for returning labels is "a list of lists", where each inner list is in the format:
(start-seconds end-seconds label-text)
The start and end times are relative to the selection start.

Example - label the current selection:

Code: Select all

;type analyze

(setf start (get '*selection* 'start))
(setf end (get '*selection* 'end))

;calculate the length
(setf duration (- end start))

; make the label. 
; Relative start time = 0
; Relative end time = duration
(list (list 0 duration "Label  Text"))
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

bigboss97
Posts: 42
Joined: Sat Feb 08, 2020 6:28 am
Operating System: Windows 10

Re: Convert Label text to LRC file

Post by bigboss97 » Wed Mar 24, 2021 9:38 pm

steve wrote:
Wed Mar 24, 2021 12:19 pm
currently there isn't a GetInfo: option to get the selection time (or even the cursor position).
Thanks for your response. Back to the drawing board... :-)

My initial idea was... user inserts labels via GUI and the script modifies the labels (by reading existing label track and generate a new one). Then I thought that script can insert labels, too. But user has to tell the position.
Looks like I have to combine the two ideas. User insert labels as markers. Script reads the markers and populate lyrics accordingly.
Any input is welcome :)

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

Re: Convert Label text to LRC file

Post by steve » Wed Mar 24, 2021 10:33 pm

bigboss97 wrote:
Wed Mar 24, 2021 9:38 pm
My initial idea was... user inserts labels via GUI and the script modifies the labels (by reading existing label track and generate a new one). Then I thought that script can insert labels, too. But user has to tell the position.
Perhaps this post will give you some ideas: viewtopic.php?p=420490#p420490
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

bigboss97
Posts: 42
Joined: Sat Feb 08, 2020 6:28 am
Operating System: Windows 10

Re: Convert Label text to LRC file

Post by bigboss97 » Thu Mar 25, 2021 11:44 am

I'm now trying to use AddLabelPlaying:. Unfortunately, playing stops as soon as I apply SetLabel:.
I guess this is a nature of audacity, not a bug. Looks like I have to add all empty labels and then apply SetLabel:.

bigboss97
Posts: 42
Joined: Sat Feb 08, 2020 6:28 am
Operating System: Windows 10

Re: Convert Label text to LRC file

Post by bigboss97 » Sun May 09, 2021 2:36 am

I've almost everything done. But there's one issue...
I can't send SetLabel with leading or trailing spaces. They will be trimmed automatically. But this is accepted if it's done via GUI. Is this a bug?
It doesn't work in my script. So I tested it with pipeclient.py, same result:

Code: Select all

Enter command or 'Q' to quit: SetLabel: Text="   x   z   " Label=1
Sending command: SetLabel: Text="   x   z   " Label=1

Post Reply