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.
Post Reply
bigboss97
Posts: 45
Joined: Sat Feb 08, 2020 6:28 am
Operating System: Windows 10

Convert Label text to LRC file

Post by bigboss97 » Sat Feb 08, 2020 6:36 am

I'm using v2.3.3. I want to create CD+G file using the label information.
Is there a tool which can convert the label text file to LRC format?

Thanks in advance

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

Re: Convert Label text to LRC file

Post by steve » Sat Feb 08, 2020 10:01 pm

I don't know of any ready made tools for converting labels to LRC.

If you export the label track (see: https://manual.audacityteam.org/man/fil ... ort_labels) then you could use a spreadsheet application (such as Microsoft Excel, or LibreOffice Calc) to remove the columns that are not required for LRC and to reformat the time as hh:mm:ss.
Then export as a .TXT file. Then use a plain text editor (such as NotePad++) to do a "search and replace" to add the square brackets.

See also:
https://manual.audacityteam.org/man/imp ... abels.html
and
https://en.wikipedia.org/wiki/LRC_(file_format)

Alternatively, if you know any programming languages such as Perl or Python, you could write a script to perform the necessary conversion.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

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

Re: Convert Label text to LRC file

Post by bigboss97 » Sun Feb 09, 2020 1:10 am

Thanks for the response.
steve wrote:
Sat Feb 08, 2020 10:01 pm
Alternatively, if you know any programming languages such as Perl or Python, you could write a script to perform the necessary conversion.
Yes, that was my plan. I just want to confirm what is already around and don't want to re-invent the wheel :-) because Audacity and LRC have been around for very long time.
I might consider writing a plug-in. But I'm a newbie and have to collect information first. Is this the place I have to go?
https://wiki.audacityteam.org/wiki/Crea ... wn_Plug-in
Can I find a "Hello world" example somewhere? :-)

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

Re: Convert Label text to LRC file

Post by steve » Sun Feb 09, 2020 11:48 am

Of those plug-in types, writing a "Nyquist" plug-in is by far the easiest option.

IMPORTANT
Nyquist scripts and plug-ins are written in "plain text". To write Nyquist code, you need to use a plain text editor (I recommend NotePad++ https://notepad-plus-plus.org/). Do NOT use Microsoft Word or any word processor, because these do not use plain text. Microsoft NotePad is NOT recommended as it will frequently cause strange problems due to it messing up character encoding.


We have quite a lot of information / documentation for Nyquist these days, though we are still a bit lacking in tutorials.
The "landing page" for Audacity's Nyquist documentation is this page in the Audacity manual: https://manual.audacityteam.org/man/nyquist.html
There's a list of reference documents here: viewtopic.php?f=39&t=77214 (If you are interested in working with Nyquist, it's worth bookmarking the links in that post).
bigboss97 wrote:
Sun Feb 09, 2020 1:10 am
Can I find a "Hello world" example somewhere?
At it's simplest, Nyquist can be run in the "Nyquist Prompt" https://manual.audacityteam.org/man/nyquist_prompt.html
The simplest form of "Hello World" using the Nyquist Prompt is simply:

Code: Select all

(print "Hello World")
The Nyquist Prompt is very handy for testing code and for running short snippets of code, but for more complex scripts, and for usability, there are advantages in creating a self-contained Nyquist plug-in that may be installed in Audacity.

A Nyquist plug-in is simply a plain text file, that begins with some "header" commands, followed by the Nyquist code. The "header" commands tell Audacity that the text file is a Nyquist plug-in, the name of the plug-in, the type of plug-in, and what controls ("widgets") are required in the plug-in's GUI (if any). If a GUI is defined in the header, then Audacity creates the plug-in GUI, and passes the values from the GUI to Nyquist. More details here: https://wiki.audacityteam.org/wiki/Nyqu ... _Reference

A simple "Hello World" Nyquist plug-in:

Code: Select all

;nyquist plug-in
;version 4
;type tool
;name "Hello World"
;copyright "Released under terms of the GNU General Public License version 2"

(print "Hello World")

When installed, the above plug-in will appear in the "Tools" menu as "Hello World".


A simple "Hello World" plug-in with a GUI:

Code: Select all

;nyquist plug-in
;version 4
;type tool
;name "Hello World GUI"
;copyright "Released under terms of the GNU General Public License version 2"

;control text "Enter text" string "" "Hello World"
(print text)

9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

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

Re: Convert Label text to LRC file

Post by steve » Sun Feb 09, 2020 5:37 pm

As this is a bit tricky for a first Nyquist program, here's some code to help you along. It is not a full plug-in, but it can be run in the Nyquist Prompt and I think it will do most of what you want.

Code: Select all

;type tool
;debugflags trace

;; Format time (seconds) as mm:ss.xx
(defun time-format (sec)
  (let* ((seconds (truncate sec))
         (mm (truncate (/ seconds 60)))
         (ss (rem seconds 60))
         (xx (round (* (- sec seconds) 100))))
    (format nil "~a:~a.~a" (pad mm) (pad ss) (pad xx))))

;; Reurn number as string with at least 2 digits
(defun pad (num)
  (format nil "~a~a" (if (< num 10) 0 "") num))

;; Get labels from first label track
(let ((labels (second (first (aud-get-info "labels")))))
  (dolist (label labels)
    (setf time (time-format (first label)))
    (format t "[~a] : ~s~%" time (third label))))

(format nil "Click OK to view LRC.")

9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

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

Re: Convert Label text to LRC file

Post by bigboss97 » Sun Feb 09, 2020 11:30 pm

Thank you so much. That's a lot of information. I'll try to work on that.

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

Re: Convert Label text to LRC file

Post by bigboss97 » Tue Feb 11, 2020 3:19 am

steve wrote:
Sun Feb 09, 2020 5:37 pm
As this is a bit tricky for a first Nyquist program, here's some code to help you along. It is not a full plug-in, but it can be run in the Nyquist Prompt and I think it will do most of what you want.
Great! You basically have done all the work :lol: Thank you so much!
I have now updated the output format a little to be able to feed the file to KarLyricEditor where I can then export to CD+G etc.

Code: Select all

;type tool
;debugflags trace

;; Format time (seconds) as mm:ss.xx
(defun time-format (sec)
  (let* ((seconds (truncate sec))
         (mm (truncate (/ seconds 60)))
         (ss (rem seconds 60))
         (xx (round (* (- sec seconds) 100))))
    (format nil "~a:~a.~a" (pad mm) (pad ss) (pad xx))))

;; Reurn number as string with at least 2 digits
(defun pad (num)
  (format nil "~a~a" (if (< num 10) 0 "") num))

;; Get labels from first label track
( format t "[ti:]~%[ar:]")
(let ((labels (second (first (aud-get-info "labels")))))
  (dolist (label labels)
    (setf timeS (time-format (first label)))
    (setf timeE (time-format (second label)))
;;    (format t "[~a] : ~s~%" time (third label))))
    (format t (if (string= (third label) "^") "~%[~a]" "<~a>~a<~a>") timeS (third label) timeE)))

(format nil "Click OK to view LRC.")
Need one more thing...
How do I popup a dialog and allow user to save the output to a file?

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

Re: Convert Label text to LRC file

Post by steve » Tue Feb 11, 2020 9:03 am

bigboss97 wrote:
Tue Feb 11, 2020 3:19 am
How do I popup a dialog and allow user to save the output to a file?
If the plug-in defines one or more "widgets" (GUI controls), then a GUI is created. See: https://wiki.audacityteam.org/wiki/Nyqu ... ce#widgets

The "File button widget" is the most complex and difficult to use of all the Nyquist plug-in widgets. See:
https://wiki.audacityteam.org/wiki/Nyqu ... ton_Widget
and
https://wiki.audacityteam.org/wiki/Nyqu ... n_Tutorial
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

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

Re: Convert Label text to LRC file

Post by bigboss97 » Tue Feb 11, 2020 11:16 pm

Thank you for all the links. I'm going to work on that.

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

Re: Convert Label text to LRC file

Post by bigboss97 » Wed Feb 12, 2020 6:20 am

I got stuck. I tried to google a solution without success :(
I added following piece of code:

Code: Select all

;control fName "Select file" file "" "*default*/karaoke.lrc" "LyRiCs|*.lrc;*.LRC|All files|*.*;*" "save,overwrite"
(format nil "Export LRC to ~s" fName)
(with-open-file(str fName :direction :output :if-exists :supersede :if-does-not-exist :create)
  (format str "write anything ~%"))
I'm testing with writing a single line and received:

Code: Select all

error: unbound function - WITH-OPEN-FILE
if continued: try evaluating symbol again
1>
Not sure what this message means. I was only able to find information about "unbound variables".
I also tried with a fixed path.

Post Reply